java通过YouTube上的链接在webview中显示一个视频 6 小时,5 分钟 Questions & Answers 314 我想在webview的应用程序中显示YouTube上的视频,但我想在没有其他视频的情况下显示它,我不想只通过视频的链接来使用YouTube APl
# 1 楼答案 这个库对我来说很好,请检查:android-youtube-player 在gradle文件中添加它的依赖项 dependencies { implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:9.0.1' } 为了开始使用播放器,你需要在布局中添加YouTubePlayerView <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 youtubePlayerView = findViewById(R.id.youtube_player_view); getLifecycle().addObserver(youtubePlayerView); youtubePlayerView.initialize(new YouTubePlayerInitListener() { @Override public void onInitSuccess(@NonNull final YouTubePlayer initializedYouTubePlayer) { initializedYouTubePlayer.addListener(new AbstractYouTubePlayerListener() { @Override public void onReady() { String videoId = "6JYIGclVQdw"; initializedYouTubePlayer.loadVideo(videoId, 0); } }); } }, true); 这就是你所需要的,YouTube视频正在你的应用程序中播放
# 1 楼答案
这个库对我来说很好,请检查:android-youtube-player
在gradle文件中添加它的依赖项
为了开始使用播放器,你需要在布局中添加YouTubePlayerView
在代码中获取对YouTubePlayerView的引用并初始化它
这就是你所需要的,YouTube视频正在你的应用程序中播放