我正嘗試在視頻Android視頻中播放YouTube視頻。這是給不能播放這個視頻。我試圖像下面..Android VideoView YouTube視頻 - 無法播放此視頻錯誤
MainActivity.java
public class MainActivity extends AppCompatActivity {
// Widgets
private VideoView vv_youtube;
// Variables
private String base_url = "https://www.youtube.com/watch?v=K8lppDEOkcM";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vv_youtube = (VideoView) findViewById(R.id.vv_youtube);
Uri video = Uri.parse(base_url);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(vv_youtube);
vv_youtube.requestFocus();
vv_youtube.setMediaController(mediaController);
vv_youtube.setVideoURI(video);
vv_youtube.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer arg0) {
vv_youtube.start();
}
});
vv_youtube.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
Log.e("Error is: ", String.valueOf(extra));
return false;
}
});
vv_youtube.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
Log.e("Complete is: ", mp.toString());
}
});
}
}
logcat的
二月11日至19日:21:45.741 21929-21961/com.example.inbridge08。 videoviewyoutube I/OpenGLRenderer:初始化的EGL,版本1.4 11-19 02:21:45.772 21929-21961/com.example.inbridge08.videoviewyoutube D/OpenGLRenderer:啓用調試模式0 11-19 02:21:45.799 21929-21961/com .example.inbridge08.videoviewyoutube W/EGL_emulation:eglSurfaceAttrib not implemented 11-19 02:21: 45.799 21929-21961/com.example.inbridge08.videoviewyoutube W/OpenGLRenderer:Failed to set EGL_SWAP_BEHAVIOR on surface 0xe2b19220,error = EGL_SUCCESS 11-19 02:21:45.898 21929-21929/com.example.inbridge08.videoviewyoutube D/MediaPlayer:無法在客戶端打開文件,嘗試服務器端11-19 02:21:46.421 21929-21947/com.example.inbridge08.videoviewyoutube E/MediaPlayer:error(1,-2147483648)11-19 02:21:46.421 21929-21929/com.example.inbridge08.videoviewyoutube E/MediaPlayer:錯誤(1,-2147483648)11-19 02:21:46.421 21929-21929/com.example.inbridge08.videoviewyoutube D/VideoView:Error:1, - 2147483648 11-19 02:21:46.421 21929-21929/com.example.inbridge08.videoviewyoutube E/Error is :: -2147483648
[11-19 02:21:46.513 82:82 D /]插座斷開連接
我在谷歌搜索了兩天,然後決定必須使用YouTube Android播放器API在視頻視圖中播放YouTube視頻。如果我將網址替換爲其他網址(不是YouTube視頻網址)它工作正常。
我在模擬器和設備上都試過。不適用於兩者。
在此先感謝!