我已经设法下载我的视频设备,但不能再访问它,以播放它在我的应用程序。我使用生成的uri将我的视频引用回videoView,但是在
根据我的日志消息,downloadManager.getUriForDownloadedFile(reference);是空的。
我做错了什么?
公开无效saveLocal(视图v){
downloadManager= (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
String url= "http://adme360.otscom.net/tim10.mp4";
uris= Uri.parse(url);
DownloadManager.Request request= new DownloadManager.Request(uris);
request.setNotificationVisibility(Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
Long reference=downloadManager.enqueue(request);
Toast.makeText(this,""+reference,Toast.LENGTH_LONG);
uri= downloadManager.getUriForDownloadedFile(reference);
Log.d("REFERENCE", ""+uri);
}
public void playLocal(View v){
video.setVideoURI(uri);
video.start();
}发布于 2018-02-08 18:39:33
下载是异步下降的。视频是在另一个线程上下载的。下载完成后,您需要注册一个广播接收器以获得回调。Quoting from answer from this question
下载完成时,下载管理器发送的广播意图操作,因此您需要在下载完成时注册接收器: 注册接收者
registerReceiver(onComplete, newIntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));和一个BroadcastReciever处理程序
BroadcastReceiver onComplete=new BroadcastReceiver() {
public void onReceive(Context ctxt, Intent intent) {
// your code
}
};`https://stackoverflow.com/questions/48692410
复制相似问题