Please note that the YouTube Android Player API has been deprecated and is no longer recommended for use. As a result, YouTubePlayerView will also be deprecated. Instead, you can migrate to the YouTube IFrame Player API.
- YouTube Player API is too old version
: Never updated from 2015/10/12 - There are 3 problems with YouTube Player API library.
- We should use Jar library file, not like
implementation xxxx
- That is old way and it makes difficult to manage the library
- If you want YouTube player with another view, you have to use
YouTubePlayerFragment
(Or you have to extendYouTubeBaseActivity
)
<FrameLayout
android:id="@+id/youtube_player_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
val youtubePlayerFragment = YouTubePlayerSupportFragment()
fragmentManager.beginTransaction()
.replace(binding.youtubePlayerContainer.id, youtubePlayerFragment)
.commitAllowingStateLoss()
youtubePlayerFragment.initialize(...)
- Furthermore if you use
androidx
package, you can not useYouTubePlayerFragment
. androidx.fragment.app.FragmentManager
needandroidx.fragment.app.Fragment
, butYouTubePlayerFragment
isandroid.app.Fragment
- You can find many question about this issue
: Youtube player support fragment no longer working on Android studio 3.2 (androidx)
: YoutubeAndroidPlayerAPI error after migrating to AndroidX in Android Studio
dependencies {
implementation 'kr.co.prnd:youtube-player-view:x.x.x'
//implementation 'kr.co.prnd:youtube-player-view:1.3.0'
}
If you think this library is useful, please press star button at upside.
- You can use 2 style
<kr.co.prnd.YouTubePlayerView
android:id="@+id/you_tube_player_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:videoId="VIDEO_ID" />
<kr.co.prnd.YouTubePlayerView
android:id="@+id/you_tube_player_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
val youTubePlayerView:YouTubePlayerView = findViewById(R.id.you_tube_player_fragment_view)
youTubePlayerView.play(VIDEO_ID)
- If you want use this
YouTubePlayerView
in fragment, you have to usefragment
attribute in xml
<kr.co.prnd.YouTubePlayerView
android:id="@+id/you_tube_player_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:fragment="com.example.youtubeplayerview.Sample2Fragment" />
- If you use Proguard, you have to add your fragment class name in your
proguard-rules.pro
file
-keepnames class com.example.youtubeplayerview.Sample2Fragment
- This is a very strange thing.
- When we use youtube player api, you can use any developer key without empty string
- So
YouTubePlayerView
set developer key itself - Check this code
Copyright 2019 PRNDcompany
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.