Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support signed url #245

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.android.tools.build:gradle:3.3.2'
}
}

allprojects {
repositories {
google()
jcenter()
}
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Apr 18 11:58:38 MSK 2017
#Tue Apr 09 10:31:28 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
36 changes: 10 additions & 26 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.novoda:bintray-release:0.4.0'
}
}

apply plugin: 'com.android.library'
apply plugin: 'idea'
apply plugin: 'bintray-release'
//apply plugin: 'idea'

android {
compileSdkVersion 23
compileSdkVersion 26
buildToolsVersion '25.0.2'

defaultConfig {
minSdkVersion 9
targetSdkVersion 23
targetSdkVersion 26
versionCode 22
versionName '2.7.1'
}
Expand All @@ -28,22 +19,15 @@ android {
}
}

idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
//idea {
// module {
// downloadJavadoc = true
// downloadSources = true
// }
//}

dependencies {
compile 'org.slf4j:slf4j-android:1.7.21'
}

publish {
userOrg = 'alexeydanilov'
groupId = 'com.danikula'
artifactId = 'videocache'
publishVersion = android.defaultConfig.versionName
description = 'Cache support for android VideoView'
website = 'https://github.com/danikula/AndroidVideoCache'
}

5 changes: 4 additions & 1 deletion library/src/main/java/com/danikula/videocache/Config.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.danikula.videocache;

import com.danikula.videocache.extend.IHttpUrlSourceMaker;
import com.danikula.videocache.file.DiskUsage;
import com.danikula.videocache.file.FileNameGenerator;
import com.danikula.videocache.headers.HeaderInjector;
Expand All @@ -19,13 +20,15 @@ class Config {
public final DiskUsage diskUsage;
public final SourceInfoStorage sourceInfoStorage;
public final HeaderInjector headerInjector;
public final IHttpUrlSourceMaker sourceMaker;

Config(File cacheRoot, FileNameGenerator fileNameGenerator, DiskUsage diskUsage, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
Config(File cacheRoot, FileNameGenerator fileNameGenerator, DiskUsage diskUsage, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector,IHttpUrlSourceMaker sourceMaker) {
this.cacheRoot = cacheRoot;
this.fileNameGenerator = fileNameGenerator;
this.diskUsage = diskUsage;
this.sourceInfoStorage = sourceInfoStorage;
this.headerInjector = headerInjector;
this.sourceMaker = sourceMaker;
}

File generateCacheFile(String url) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private void responseWithCache(OutputStream out, long offset) throws ProxyCacheE
}

private void responseWithoutCache(OutputStream out, long offset) throws ProxyCacheException, IOException {
HttpUrlSource newSourceNoCache = new HttpUrlSource(this.source);
HttpUrlSource newSourceNoCache = this.source.copy();
try {
newSourceNoCache.open((int) offset);
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.net.Uri;

import com.danikula.videocache.extend.IHttpUrlSourceMaker;
import com.danikula.videocache.file.DiskUsage;
import com.danikula.videocache.file.FileNameGenerator;
import com.danikula.videocache.file.Md5FileNameGenerator;
Expand Down Expand Up @@ -353,6 +354,7 @@ public static final class Builder {
private DiskUsage diskUsage;
private SourceInfoStorage sourceInfoStorage;
private HeaderInjector headerInjector;
private IHttpUrlSourceMaker sourceMaker;

public Builder(Context context) {
this.sourceInfoStorage = SourceInfoStorageFactory.newSourceInfoStorage(context);
Expand Down Expand Up @@ -419,6 +421,17 @@ public Builder maxCacheFilesCount(int count) {
return this;
}

/**
* Set a http source maker which can build your defined http source.This give you a change to
* change the http request,such as sign url at so on.
* @param sourceMaker
* @return
*/
public Builder sourceMaker(IHttpUrlSourceMaker sourceMaker) {
this.sourceMaker = sourceMaker;
return this;
}

/**
* Set custom DiskUsage logic for handling when to keep or clean cache.
*
Expand Down Expand Up @@ -452,7 +465,7 @@ public HttpProxyCacheServer build() {
}

private Config buildConfig() {
return new Config(cacheRoot, fileNameGenerator, diskUsage, sourceInfoStorage, headerInjector);
return new Config(cacheRoot, fileNameGenerator, diskUsage, sourceInfoStorage, headerInjector,sourceMaker);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ public int getClientsCount() {
}

private HttpProxyCache newHttpProxyCache() throws ProxyCacheException {
HttpUrlSource source = new HttpUrlSource(url, config.sourceInfoStorage, config.headerInjector);
HttpUrlSource source = null;
if(null != config.sourceMaker)
{
source = config.sourceMaker.createHttpUrlSource(url, config.sourceInfoStorage, config.headerInjector);
}
else
{
source = new HttpUrlSource(url, config.sourceInfoStorage, config.headerInjector);
}
FileCache cache = new FileCache(config.generateCacheFile(url), config.diskUsage);
HttpProxyCache httpProxyCache = new HttpProxyCache(source, cache);
httpProxyCache.registerCacheListener(uiCacheListener);
Expand Down
19 changes: 12 additions & 7 deletions library/src/main/java/com/danikula/videocache/HttpUrlSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
*/
public class HttpUrlSource implements Source {

private static final Logger LOG = LoggerFactory.getLogger("HttpUrlSource");
protected static final Logger LOG = LoggerFactory.getLogger("HttpUrlSource");

private static final int MAX_REDIRECTS = 5;
private final SourceInfoStorage sourceInfoStorage;
private final HeaderInjector headerInjector;
private SourceInfo sourceInfo;
private HttpURLConnection connection;
private InputStream inputStream;
protected static final int MAX_REDIRECTS = 5;
protected final SourceInfoStorage sourceInfoStorage;
protected final HeaderInjector headerInjector;
protected SourceInfo sourceInfo;
protected HttpURLConnection connection;
protected InputStream inputStream;

public HttpUrlSource(String url) {
this(url, SourceInfoStorageFactory.newEmptySourceInfoStorage());
Expand All @@ -64,6 +64,11 @@ public HttpUrlSource(HttpUrlSource source) {
this.headerInjector = source.headerInjector;
}

public HttpUrlSource copy()
{
return new HttpUrlSource(this);
}

@Override
public synchronized long length() throws ProxyCacheException {
if (sourceInfo.length == Integer.MIN_VALUE) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.danikula.videocache.extend;

import com.danikula.videocache.HttpUrlSource;
import com.danikula.videocache.Source;
import com.danikula.videocache.headers.HeaderInjector;
import com.danikula.videocache.sourcestorage.SourceInfoStorage;

public interface IHttpUrlSourceMaker
{
HttpUrlSource createHttpUrlSource(String url, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector);
}
17 changes: 9 additions & 8 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repositories {
}

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
//apply plugin: 'com.neenbedankt.android-apt'

android {
compileSdkVersion 23
Expand All @@ -27,18 +27,19 @@ android {
}
}

apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName android.defaultConfig.applicationId
}
}
//apt {
// arguments {
// androidManifestFile variant.outputs[0].processResources.manifestFile
// resourcePackageName android.defaultConfig.applicationId
// }
//}

dependencies {
// compile project(':library')
compile 'com.android.support:support-v4:23.1.0'
compile 'org.androidannotations:androidannotations-api:3.3.2'
compile 'com.danikula:videocache:2.7.1'
compile 'com.viewpagerindicator:library:2.4.2-SNAPSHOT@aar'
apt 'org.androidannotations:androidannotations:3.3.2'
// apt 'org.androidannotations:androidannotations:3.3.2'
annotationProcessor 'com.google.dagger:dagger-compiler:2.12'
}
4 changes: 3 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
include ':sample', ':library', ':test'
include ':sample'
include ':library'
include ':test'
2 changes: 0 additions & 2 deletions test/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.danikula.videocache.test">

<uses-sdk android:minSdkVersion="18" />

<application />

</manifest>