gpt4 book ai didi

android - 来自 http url 的在线视频流,在 android 应用程序中具有缓存

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:08:56 26 4
gpt4 key购买 nike

在我的应用程序中,我以渐进的方式向用户展示来自在线资源的视频(每个视频都有一个 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();
}
}

关于android - 来自 http url 的在线视频流,在 android 应用程序中具有缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23134705/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com