我使用媒體播放器,試圖從youtube上下載視頻和音頻流。
使用 url如何實現呢?
我使用的例子是:
http://www.youtube.com/watch?v=SgGhtjKWLOE&feature=feedrec
但是得到的 LogCat Error:
01-03 22:22:30.140: INFO/AwesomePlayer(85): setDataSource_l('http://www.youtube.com/watch?v=I3jv0IF9n6A')
01-03 22:22:30.140: INFO/NuHTTPDataSource(85): connect to www.youtube.com:80/watch?v=I3jv0IF9n6A @0
01-03 22:22:30.250: INFO/NuHTTPDataSource(85): connect to m.youtube.com:80/watch?desktop_uri=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DI3jv0IF9n6A&v=I3jv0IF9n6A&gl=US @0
09-04 22:22:30.410: INFO/NuHTTPDataSource(85): connect to m.youtube.com:80/#/watch?desktop_uri=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DI3jv0IF9n6A&v=I3jv0IF9n6A&gl=US @0
01-03 22:22:30.570: INFO/NuHTTPDataSource(85): Chunked transfer encoding applied.
01-03 22:22:30.570: WARN/NuHTTPDataSource(85): Server did not give us the content length!
01-03 22:22:31.000: INFO/NuCachedSource2(85): ERROR_END_OF_STREAM
01-03 22:22:31.630: ERROR/MediaPlayer(8404): error (1, -2147483648)
01-03 22:22:31.630: WARN/System.err(8404): java.io.IOException: Prepare failed.: status=0x1
01-03 22:22:31.630: WARN/System.err(8404): at android.media.MediaPlayer.prepare(Native Method)
01-03 22:22:31.630: WARN/System.err(8404): at com.fttech.example.youtube.example.AccessibleYouTube.watchVideo(AccessibleYouTube.java:139)
01-03 22:22:31.630: WARN/System.err(8404): at java.lang.reflect.Method.invokeNative(Native Method)
01-03 22:22:31.630: WARN/System.err(8404): at java.lang.reflect.Method.invoke(Method.java:491)
01-03 22:22:31.630: WARN/System.err(8404): at android.view.View$1.onClick(View.java:2678)
01-03 22:22:31.630: WARN/System.err(8404): at android.view.View.performClick(View.java:3110)
01-03 22:22:31.630: WARN/System.err(8404): at android.view.View$PerformClick.run(View.java:11928)
01-03 22:22:31.630: WARN/System.err(8404): at android.os.Handler.handleCallback(Handler.java:587)
01-03 22:22:31.630: WARN/System.err(8404): at android.os.Handler.dispatchMessage(Handler.java:92)
如果你想使用MediaPlayer對象,然後使用以下的調用方法:
MediaPlayer mp = new MediaPlayer();
mp.setDataSource("http://www.youtube.com/watch?v=SgGhtjKWLOE&feature=feedrec");
mp.prepare();
mp.start();
否則,如果你不介意使用youtube程序,用下面的代碼:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=SgGhtjKWLOE&feature=feedrec")));