我在下载视频时如何解决下载管理器问题?

时间:2019-06-09 09:41:08

标签: android

我正在制作一个使用链接下载YouTube视频的应用。视频下载成功,我在视频视图中显示该视频,但是在我的手机下载中,视频未打开。当我单击视频时,它说(视频已被删除,移动或重命名。请点击\ download下载文件),然后再次下载。它说(找不到要执行此任务的应用程序。)

我搜索了很多,但没有找到任何解决方法。

    String youtubeLink = 
           "https://www.youtube.com/watchv=1yDSxu9o84Q&t=6s";
  DownloadManager downloadManager;
  String downloadUrl;
  long id;
  @Override
   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);
    YouTubeUriExtractor ytEx = new YouTubeUriExtractor(this) {
        @Override
        public void onUrisAvailable(String videoId, String videoTitle, 
   SparseArray<YtFile> ytFiles) {
            if (ytFiles != null) {
                int itag = 22;
 // Here you can get download url
                downloadUrl = ytFiles.get(itag).getUrl();
                Toast.makeText(getApplicationContext(),"lik" 
 +downloadUrl,Toast.LENGTH_LONG).show();
                downloadManager= 
 (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
                DownloadManager.Request request=new 
 DownloadManager.Request(Uri.parse(downloadUrl));
                id=downloadManager.enqueue(request);
            }
        }
    };
    ytEx.execute(youtubeLink);


    BroadcastReceiver broadcastReceiver=new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {

            String action=intent.getAction();
            if(DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)){

       VideoView videoView=findViewById(R.id.video1);
                        MediaController mediaController=new 
  MediaController(getApplicationContext());
                        mediaController.setAnchorView(videoView);
                        videoView.requestFocus();
                        videoView.setVideoURI(Uri.parse(downloadUrl));
                        videoView.start();
            }
        }
    };

    registerReceiver(broadcastReceiver,new 
     IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}

我希望在手机下载中打开视频

0 个答案:

没有答案