⚠️ **Deprecation Notice
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.
implementation xxxx
YouTubePlayerFragment
(Or you have to extend YouTubeBaseActivity
)
<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(...)
androidx
package, you can not use YouTubePlayerFragment
.androidx.fragment.app.FragmentManager
need androidx.fragment.app.Fragment
, but YouTubePlayerFragment
is android.app.Fragment
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.
<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)
YouTubePlayerView
in fragment, you have to use fragment
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" />
proguard-rules.pro
file
-keepnames class com.example.youtubeplayerview.Sample2Fragment
YouTubePlayerView
set developer key itselfCopyright 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.