gpt4 book ai didi

android - 为什么 Videoview 不能播放 Youtube 视频?

转载 作者:行者123 更新时间:2023-11-29 02:04:21 26 4
gpt4 key购买 nike

我尝试在某些设备上播放来自 Youtube 的 Youtube 视频,但它们返回一个对话框:“视频无法播放”。

我已经阅读了 Youtube API 文档。

我有一个 VideoView,我将视频 Uri 设置为扩展名为 .3pg 的 url。

这是我的代码:

 VideoView videoView = (VideoView)this.findViewById(R.id.video); 
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
videoView.setVideoURI(Uri.parse("rtsp://v1.cache2.c.youtube.com/CigLENy73wIaHwmhXrOROaqgpBMYESARFEgGUgx1c2VyX3VwbG9hZHMM/0/0/0/video.3gp"));
videoView.requestFocus();
videoView.start();

我已经尝试过其他视频并且可以正常播放。我做错了什么?

最佳答案

如果嵌入视频不是您的明确要求,您为什么不直接使用 Youtube 视频 URL 启动 Intent 并让操作系统为您处理 Intent ?据我所知,这是在 android 上播放视频的最简单方法。例如,

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("Your youtube URL here"));
startActivity(intent);

有关 Android Intents 的更多信息,请参阅 this linkvogella's tutorial

关于android - 为什么 Videoview 不能播放 Youtube 视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10894633/

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