mirror of
https://github.com/zhigang1992/AndroidVideoCache.git
synced 2026-04-22 19:23:36 +08:00
🎉 VideoCache 1.0 released
This commit is contained in:
24
sample/src/main/AndroidManifest.xml
Normal file
24
sample/src/main/AndroidManifest.xml
Normal 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>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
22
sample/src/main/res/layout/activity_video.xml
Normal file
22
sample/src/main/res/layout/activity_video.xml
Normal 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>
|
||||
BIN
sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
BIN
sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.5 KiB |
3
sample/src/main/res/values/strings.xml
Normal file
3
sample/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">VideoCacheSample</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user