0

我正在开发一个 android 应用程序,我想播放来自 youtube 的流媒体视频。我读过这样的帖子:如何在我的 Android 应用程序中播放 YouTube 视频? 我尝试使用该来源:

  startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.youtube.com/watch?v=tsDYIgX_gDs")));

我在 WebView 中有视频,我可以听到声音但没有图片。这也不是我想要的,因为我希望视频在活动开始时自动开始,而不是单击按钮播放(因为我还想添加一些计数器、计时器。 . 用于其他治疗)。然后,我尝试了 MediaPlayer:

 String FILE_PATH="http://www.youtube.com/watch?v=tsDYIgX_gDs";
    MediaPlayer mp = new MediaPlayer();
    mp.setDataSource(FILE_PATH);
    mp.prepare();
    mp.start();

跳到这里来控制视频开始mp.start();。但我有这些错误:

05-20 15:36:36.279: ERROR/HTTPStream(33): recv failed, errno = 11 (Try again)
05-20 15:36:36.808: ERROR/HTTPDataSource(33): HTTP request failed w/ http status 303
05-20 15:36:36.808: ERROR/HTTPDataSource(33): retrying connection failed
05-20 15:36:41.834: ERROR/HTTPStream(33): recv failed, errno = 11 (Try again)
05-20 15:36:48.389: ERROR/HTTPStream(33): recv failed, errno = 11 (Try again)
05-20 15:36:54.913: ERROR/HTTPStream(33): recv failed, errno = 11 (Try again)
05-20 15:36:54.913: ERROR/HTTPStream(33): recv failed, errno = 9 (Bad file number)
05-20 15:36:54.918: ERROR/HTTPStream(33): recv failed, errno = 9 (Bad file number)
05-20 15:36:54.918: ERROR/HTTPStream(33): recv failed, errno = 9 (Bad file number)
05-20 15:36:54.918: ERROR/MediaPlayer(6392): error (1, -2147483648)
05-20 15:36:55.219: ERROR/MediaPlayer(6392): start called in state 0
05-20 15:36:55.219: ERROR/MediaPlayer(6392): error (-38, 0)
05-20 15:36:55.228: ERROR/MediaPlayer(6392): Error (-38,0)

有人可以帮忙吗?

4

1 回答 1

1

尝试将 Start 意图更改为:

     startActivity(new Intent(Intent.ACTION_VIEW, 
Uri.parse(String.format("http://www.youtube.com/v/%s", 
url.substring("vnd.youtube:".length(),n)));

要进行更深入的学习,请尝试以下问题:ThisThis

于 2012-05-20T16:27:30.077 回答