我正在尝试将实时流嵌入到android应用中。该代码对其他视频非常有效,但是当我输入直播频道的URL代码时无法加载。它只是继续加载。向我提出建议或嵌入实时流是否需要其他任何API。
onInitializedListener = new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.("5kbU-C0FxqA");
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
}
};
答案 0 :(得分:1)
第一个视频ID已过期,因此您需要替换另一个视频并检查年龄
我还认为您的代码应如下所示
onCreate
YouTubePlayerView youTubePlayerView = findViewById(R.id.youtube_player);
youTubePlayerView.initialize(getString(R.string.google_developer_api_key), this);
OnInitializedListener
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.loadVideo(""); // your video id
youTubePlayer.play();
}
答案 1 :(得分:1)
如果您不能使其与YouTubePlayer API一起使用,则可以考虑使用以下替代播放器:android-youtube-player。
这是播放实时视频所需要做的一切:
将播放器添加到XML:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.pierfrancescosoffritti.androidyoutubeplayer.player.YouTubePlayerView
android:id="@+id/youtube_player_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
初始化播放器并播放视频:
YouTubePlayerView youtubePlayerView = findViewById(R.id.youtube_player_view);
getLifecycle().addObserver(youtubePlayerView);
youtubePlayerView.getPlayerUIController().enableLiveVideoUI(true);
youtubePlayerView.initialize(new YouTubePlayerInitListener() {
@Override
public void onInitSuccess(@NonNull final YouTubePlayer initializedYouTubePlayer) {
initializedYouTubePlayer.addListener(new AbstractYouTubePlayerListener() {
@Override
public void onReady() {
String videoId = "2ccaHpy5Ewo";
initializedYouTubePlayer.loadVideo(videoId, 0);
}
});
}
}, true);