ability to check was content fully cached to file or not

This commit is contained in:
Alexey Danilov
2016-07-27 23:14:06 +03:00
parent eb67640212
commit cd0b4111a4
17 changed files with 99 additions and 8 deletions

View File

@@ -19,7 +19,7 @@ android {
buildToolsVersion '24'
defaultConfig {
applicationId "com.danikula.videocache.sample"
applicationId 'com.danikula.videocache.sample'
minSdkVersion 15
targetSdkVersion 23
versionCode 1
@@ -38,7 +38,7 @@ 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.3.3'
compile 'com.danikula:videocache:2.4.0'
compile 'com.viewpagerindicator:library:2.4.2-SNAPSHOT@aar'
apt 'org.androidannotations:androidannotations:3.3.2'
}

View File

@@ -5,6 +5,7 @@ import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.VideoView;
@@ -27,6 +28,7 @@ public class VideoFragment extends Fragment implements CacheListener {
@FragmentArg String url;
@FragmentArg String cachePath;
@ViewById ImageView cacheStatusImageView;
@ViewById VideoView videoView;
@ViewById ProgressBar progressBar;
@@ -45,9 +47,16 @@ public class VideoFragment extends Fragment implements CacheListener {
@AfterViews
void afterViewInjected() {
checkCachedState();
startVideo();
}
private void checkCachedState() {
HttpProxyCacheServer proxy = App.getProxy(getActivity());
boolean fullyCached = proxy.isCached(url);
setCachedState(fullyCached);
}
private void startVideo() {
HttpProxyCacheServer proxy = App.getProxy(getActivity());
proxy.registerCacheListener(this, url);
@@ -78,6 +87,7 @@ public class VideoFragment extends Fragment implements CacheListener {
@Override
public void onCacheAvailable(File file, String url, int percentsAvailable) {
progressBar.setSecondaryProgress(percentsAvailable);
setCachedState(percentsAvailable == 100);
Log.d(LOG_TAG, String.format("onCacheAvailable. percents: %d, file: %s, url: %s", percentsAvailable, file, url));
}
@@ -92,6 +102,11 @@ public class VideoFragment extends Fragment implements CacheListener {
videoView.seekTo(videoPosition);
}
private void setCachedState(boolean cached) {
int statusIconId = cached ? R.drawable.ic_cloud_done : R.drawable.ic_cloud_download;
cacheStatusImageView.setImageResource(statusIconId);
}
private final class VideoProgressUpdater extends Handler {
public void start() {

Binary file not shown.

After

Width:  |  Height:  |  Size: 379 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 265 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 242 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 417 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 672 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 855 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 789 B

View File

@@ -10,6 +10,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/cacheStatusImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:src="@drawable/ic_cloud_download" />
<SeekBar
android:id="@+id/progressBar"
style="@android:style/Widget.Holo.ProgressBar.Horizontal"