🎉 VideoCache 1.0 released

This commit is contained in:
Alexey Danilov
2015-04-01 14:24:35 +03:00
commit 70baa564c0
37 changed files with 2042 additions and 0 deletions

19
sample/build.gradle Normal file
View File

@@ -0,0 +1,19 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.danikula.videocache.sample"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
}
dependencies {
compile 'com.android.support:appcompat-v7:22.0.0'
compile project(':library')
}

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.danikula.videocache.sample">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<activity
android:name=".VideoActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -0,0 +1,75 @@
package com.danikula.videocache.sample;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.widget.ProgressBar;
import android.widget.VideoView;
import com.danikula.videocache.Cache;
import com.danikula.videocache.CacheListener;
import com.danikula.videocache.FileCache;
import com.danikula.videocache.HttpProxyCache;
import com.danikula.videocache.HttpUrlSource;
import com.danikula.videocache.ProxyCacheException;
import java.io.File;
public class VideoActivity extends ActionBarActivity implements CacheListener {
private static final String LOG_TAG = "VideoActivity";
private static final String VIDEO_CACHE_NAME = "devbytes.mp4";
private static final String VIDEO_URL = "https://dl.dropboxusercontent.com/u/15506779/persistent/proxycache/devbytes.mp4";
private VideoView videoView;
private ProgressBar progressBar;
private HttpProxyCache proxyCache;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setUpUi();
playWithCache();
}
private void setUpUi() {
setContentView(R.layout.activity_video);
videoView = (VideoView) findViewById(R.id.videoView);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
progressBar.setMax(100);
}
private void playWithCache() {
try {
Cache cache = new FileCache(new File(getExternalCacheDir(), VIDEO_CACHE_NAME));
HttpUrlSource source = new HttpUrlSource(VIDEO_URL);
proxyCache = new HttpProxyCache(source, cache);
proxyCache.setCacheListener(this);
videoView.setVideoPath(proxyCache.getUrl());
videoView.start();
} catch (ProxyCacheException e) {
// do nothing. onError() handles all errors
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (proxyCache != null) {
proxyCache.shutdown();
}
}
@Override
public void onError(ProxyCacheException e) {
Log.e(LOG_TAG, "Error playing video", e);
}
@Override
public void onCacheDataAvailable(int cachePercentage) {
progressBar.setProgress(cachePercentage);
}
}

View File

@@ -0,0 +1,22 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".VideoActivity">
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@android:style/Widget.Holo.ProgressBar.Horizontal"
android:layout_margin="16dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

View File

@@ -0,0 +1,3 @@
<resources>
<string name="app_name">VideoCacheSample</string>
</resources>