/YouTubePlayerView

Super easy Youtube Player View, not Fragment

Primary LanguageKotlin

YouTubePlayerView (Deprecated)

⚠️ **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.

What is YouTubePlayerView?

Problem 1 - Jar File

  • We should use Jar library file, not like implementation xxxx
  • That is old way and it makes difficult to manage the library

Problem 2 - Fragment style

  • If you want YouTube player with another view, you have to use 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(...)

Problem 3 - Conflict Fragment with androidx

YouTubePlayerView is super easy YouTube Player View

Setup

Gradle

Maven Central

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.


How to use

  • You can use 2 style

XML 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" />

Dynamic code style

<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)

Fragment

  • If you want use this 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" />
  • If you use Proguard, you have to add your fragment class name in your proguard-rules.pro file
-keepnames class com.example.youtubeplayerview.Sample2Fragment

FAQ

- Why don't you need a developer key?

  • 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

License

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.