Giter Club home page Giter Club logo

youtubetv's Introduction

YoutubeTV library

CircleCI Download Maven Central Codacy Badge Javadoc License

YouTube embedded player library for Android TV

Purpose

Download YoutubeTv library Showcase from Google Play :

Download YoutubeTv library Showcase from Google Play

Features

  • a custom view YoutubeTvView that embeds a Webview with Youtube iframe
  • a custom fragment YoutubeTvFragment that holds a YoutubeTvView with a media control bar (PlaybackOverlayFragment)
  • all Javascript API for iframe Embeds are available from YoutubeTvView
  • video autoplay
  • a video thumbnail is shown at the beginning waiting for the player to be ready
  • a loading progress bar is shown waiting for the PLAY status

Include in your project

with Gradle, from jcenter :

compile 'fr.bmartel:youtubetv:1.2'

Minimum SDK : 21

YoutubeTvView

YoutubeTvView is the custom view that holds Youtube iframe inside a Webview.

Layout

<fr.bmartel.youtubetv.YoutubeTvView
    android:id="@+id/youtube_video"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:yt_videoId="4a5m4qF1e6Q" />

Attribute list

attribute name format default value description
yt_videoId string Youtube video Id
yt_playlistId string playlist Id (if video is part of a playlist)
yt_videoQuality enum hd1080 suggested quality
yt_showNowPlayingCard boolean true define if now playing card must be shown or not
yt_showRelatedVideos boolean false display related video when video ends
yt_showVideoInfo boolean false show video info before playing video
yt_showControls enum none define if iframe control bar is shown (auto/always/none)
yt_autoHide enum alwaysVisible control iframe control bar visibility (auto/always/none)
yt_closedCaptions boolean false display closed captions
yt_closedCaptionLangPref string closed captions preference language
yt_playerLanguage string youtube player language
yt_videoAnnotation boolean false display video annotations
yt_debug boolean false active/disactive debug mode
yt_loadingBackgroundColor integer #00000000 set loading background color
yt_autoplay boolean true autoplay the video or initiate on click
yt_userAgentString string iphone(*) user agent string used for the Webview
yt_showBorder boolean false define if a thin border is shown when the View is selected
yt_borderWidth integer 2 selection border width in dp (no effect if showBorder not set)
yt_borderColor color Color.BLUE selection border color (no effect if showBorder not set)
yt_thumbnailQuality enum maxresdefault suggested quality for the thumbnail displayed before the video plays
yt_javascriptTimeout integer 1500 timeout value in ms for Javascript API that return values from JS side

(*) There is currently a bug on regular android user agent string that restricts video quality to large and below. The bug doesn't affect desktop, iphone or ipad user agent string. So, in order to have quality hd720 or hd1080 we must change user agent string.

  • suggested videoQuality

    • auto
    • tiny
    • small
    • medium
    • large
    • hd720
    • hd1080
    • highres
    • hd1440
    • hd2160
  • suggested thumbnailQuality

    • auto
    • hqdefault
    • mqdefault
    • sddefault
    • maxresdefault

YoutubeTvFragment

YoutubeTvFragment holds a YoutubeTvView with a PlaybackOverlayFragment that is used to display a media control bar.

Usage

  • in your Activity's onCreate :
FragmentTransaction fTransaction = getFragmentManager().beginTransaction();

Bundle args = new Bundle();
args.putString("videoId", "gdgHZi347hU");
args.putString("videoQuality", "hd1080");

YoutubeTvFragment mYtFragment = YoutubeTvFragment.newInstance(args);
fTransaction.replace(R.id.youtube_fragment, mYtFragment);
fTransaction.commit();

Proguard

The following is required to keep Javascript interface from obfuscation :

-keep class fr.bmartel.youtubetv.JavascriptInterface { *; }

-keepclassmembers,allowobfuscation class fr.bmartel.youtubetv.JavascriptInterface.** {
    <methods>;
}

External libraries

License

The MIT License (MIT) Copyright (c) 2016 Bertrand Martel

youtubetv's People

Contributors

bertrandmartel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

youtubetv's Issues

When i touch the screen it pause my player in YoutubeTvViewFullScreen

Hi,

I tried many control to make webview clickable false. But this is not working.

mWebView.setOnTouchListener(new View.OnTouchListener() {
@OverRide
public boolean onTouch(View v, MotionEvent event) {
return false;
}
});
mWebView.setClickable(false);
mWebView.setEnabled(false);
mWebView.setFocusableInTouchMode(false);
mWebView.setFocusable(false);

Also i tried to make the whole view clickable false

View view =inflate(getContext(), R.layout.youtube_view, this);
view.setClickable(false);
view.setEnabled(false);
view.setFocusableInTouchMode(false);
view.setFocusable(false);
view.setOnTouchListener(new View.OnTouchListener() {
@OverRide
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});

I do not want to play pause video when user click on video. But it automatically pause the video .
Please help me

Media session is not destroyed when exiting activity

I'm having a probem when using this library.
When I exit the activity, I'm calling the following:

fragment.closePlayer(); // does nothing

This one always return null for the view.

YoutubeTvView view = (YoutubeTvView) findViewById(fr.bmartel.youtubetv.R.id.youtubetv_view);
        if (view != null) {
            view.stopVideo();
            view.closePlayer();
        }

This is the activity I'm using:

public class YoutubePlaybackActivity extends Activity {

    private static final String TAG = YoutubePlaybackActivity.class.getSimpleName();

    public static final String EXTRA_VIDEO_ID = "videoId";
    public static final String EXTRA_CONTENT_LIST = "ContentList";

    private YouTubePlayerView mYouTubePlayerView;

    private static final String API_KEY = "AIzaSyBgDhyTYKAIfDlHODy-r6BopuhTTNp7nro";
    private YoutubeTvFragment mFragment;

    public void toggleHideyBar() {

        // The UI options currently enabled are represented by a bitfield.
        // getSystemUiVisibility() gives us that bitfield.
        int uiOptions = getWindow().getDecorView().getSystemUiVisibility();
        int newUiOptions = uiOptions;
        boolean isImmersiveModeEnabled =
                ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);
        if (isImmersiveModeEnabled) {
            Log.i(TAG, "Turning immersive mode mode off. ");
        } else {
            Log.i(TAG, "Turning immersive mode mode on.");
        }

        newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
        newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
        newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

        getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_youtube_playback);
        toggleHideyBar();
        Bundle args = new Bundle();
        args.putString("videoId",      getIntent().getStringExtra(EXTRA_VIDEO_ID));
        args.putString("videoQuality", "hd1080");
        mFragment = YoutubeTvFragment.newInstance(args);

        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.add(R.id.root, mFragment);
        transaction.commit();
    }

    @Override
    protected void onDestroy() {
        if (mFragment != null) {
            mFragment.closePlayer();
        }
        YoutubeTvView view = (YoutubeTvView) findViewById(fr.bmartel.youtubetv.R.id.youtubetv_view);
        if (view != null) {
            view.stopVideo();
            view.closePlayer();
        }
        super.onDestroy();
    }
}

is there something I'm forgetting about?

Thanks

No player error interface.

Hi, do you plan on exposing an interface for error handling? Now there is no way to know if the embedded video has been deleted.

AndroidX Support

If I need to covert this library to android X then How can I do it?

Discontinued?

Any plans to upgrade this useful lib?
Needs to be compatible with the new androidx Leanback lib.
I did some experiments to make a migration, but I'm not able to play any youtube videos.

AAPT: Attribute already defined with incompatible format

I am getting this error while including just the dependency

androidtv/tv/build/intermediates/res/merged/debug/values/values.xml:546: AAPT: Attribute "borderWidth" already defined with incompatible format.
androidtv/tv/build/intermediates/res/merged/debug/values/values.xml:436: AAPT: Original attribute defined here.
androidtv/tv/build/intermediates/res/merged/debug/values/values.xml:546: error: Attribute "borderWidth" already defined with incompatible format.
androidtv/tv/build/intermediates/res/merged/debug/values/values.xml:436: Original attribute defined here.

Stopped working?

Hi. Are you still maintaining this? It has stopped working for us on Android TV. The backdrop thumb loads but then it just sits there with the spinner. The "PlayerReady" event fires but player status never changes and it never starts playing.

Only error is:

I/chromium: [INFO:CONSOLE(751)] "Unrecognized feature: 'picture-in-picture'.", source: https://www.youtube.com/s/player/02486e7d/www-widgetapi.vflset/www-widgetapi.js (751)

Visible More videos in video view

Hello.

I try use this library in my proyecto but when i pause in the video is visible to see the list more video and the options shared and see later. is posible hide that?

and How i can do that?

I use YoutubeTvFullScreen example.

device-2020-02-03-172047

Endless Buffering, cant change quality

So I got a video, in debug mode it says it is loaded but there is endless buffering to the point that the video wont move one second. Weird thing is that the captions automatically load. Ive tried changing quality to tiny but it doesnt change it accordiding to the debug vieew.

Support for live YouTube video?

Hi. Thank you very much for building this library.
I got a question tho, is there any where I can play live YouTube video using this library of yours?
Or anyone that already extended the library that willing to share.
Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.