Bha*_*rat 4 android video-streaming progressive-download android-mediaplayer
在我的应用程序中,我以渐进的方式从在线来源向用户显示视频(每个视频都有一个 Http url)。SurfaceView 和 MediaPlayer 结合使用以及 VideoView 作为替代方案是完全可能的。但我想将流媒体视频保留在缓存中以备将来使用[无需单独调用下载视频,因为它已经在流媒体播放时由 MediaPlayer 或 VideoView 下载]
关于从 MediaPlayer 缓冲的流中保存视频的任何想法?
只需使用AndroidVideoCache:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
try {
Cache cache = new FileCache(new File(getExternalCacheDir(), VIDEO_CACHE_NAME));
HttpUrlSource source = new HttpUrlSource(VIDEO_URL);
proxyCache = new HttpProxyCache(source, cache);
videoView.setVideoPath(proxyCache.getUrl());
videoView.start();
} catch (ProxyCacheException e) {
Log.e(LOG_TAG, "Error playing video", e);
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (proxyCache != null) {
proxyCache.shutdown();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4701 次 |
| 最近记录: |