question

susman avatar image
susman asked ·

Issue with playing youtube videos in Fire TV

I am developing an app that takes youtube video id's from the backend and it should play the videos from the queue automatically without the intervention of the user. But these are the challenges that I Faced with different approaches.

1. Using Youtube API:- This is not supported by FireTV and my App is not approved in the Amazon store.

2. Using Webview :-

  • When I use the video URL as "https://www.youtube.com/watch?v=ajMpIN6BvQE" youtube videos are started playing automatically. But I am seeing the recommendations to the video and unable to get rid of these recommendations automatically
  • When I use the video URL as "https://www.youtube-nocookie.com/embed/ajMpIN6BvQE" it stopped showing the recommendations but the challenge here is I am unable to play the videos automatically. It is forcing the user to click on the play button explicitly. bellow is the code I have used
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.Toast;

import androidx.annotation.Nullable;


import static com.parse.Parse.getApplicationContext;

public class WebViewActivity extends Activity {
    WebView webView;
    WebChromeClient.CustomViewCallback customViewCallback;
    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_webview);
        webView = findViewById(R.id.webView);
        webView.setWebViewClient(new WebViewClient());
        ChromeClient chromeClient= new ChromeClient();
        webView.setWebChromeClient(chromeClient);
    
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setAllowFileAccess(true);
        webSettings.setAppCacheEnabled(true);


       // webView.loadUrl("https://www.youtube-nocookie.com/embed/ajMpIN6BvQE");
        webView.loadUrl("https://www.youtube.com/watch?v=ajMpIN6BvQE");
        webSettings.setMediaPlaybackRequiresUserGesture(false);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
            }
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
              
            }
        });
    }
    @Override
    public void onPause() {
        webView.onPause();
        super.onPause();
    }
    @Override
    public void onDestroy() {
        webView.destroy();
        super.onDestroy();
    }

    @Override
    public void onStop() {
        super.onStop();
    }
    @Override
    protected void onRestart() {
        super.onRestart();
    }
    public void onBackPressed() {
        webView.stopLoading();
        finish();
    }
    @Override
    protected void onStart() {
        super.onStart();
    }
    public class ChromeClient extends WebChromeClient {
        private View mCustomView;
        private WebChromeClient.CustomViewCallback mCustomViewCallback;
        protected FrameLayout mFullscreenContainer;
        private int mOriginalOrientation;
        private int mOriginalSystemUiVisibility;

        ChromeClient() {}

        public Bitmap getDefaultVideoPoster()
        {
            if (mCustomView == null) {
                return null;
            }
            return BitmapFactory.decodeResource(getApplicationContext().getResources(), 2130837573);
        }

        @Override
        public void onHideCustomView()
        {
            ((FrameLayout)getWindow().getDecorView()).removeView(this.mCustomView);
            this.mCustomView = null;
            getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility);
            setRequestedOrientation(this.mOriginalOrientation);
            this.mCustomViewCallback.onCustomViewHidden();
            this.mCustomViewCallback = null;
        }

        @Override
        public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback)
        {
            if (this.mCustomView != null)
            {
                onHideCustomView();
                return;
            }
            this.mCustomView = paramView;
            this.mOriginalSystemUiVisibility = getWindow().getDecorView().getSystemUiVisibility();
            this.mOriginalOrientation = getRequestedOrientation();
            this.mCustomViewCallback = paramCustomViewCallback;
            ((FrameLayout)getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1));
            getWindow().getDecorView().setSystemUiVisibility(3846 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        }

    }
}


Help me with the understanding is it possible to achieve in FireTV's or not. I am spending lot of time to achieve this work. Thanks. @Ross , @Levon@Amazon



fire tvvideoapp
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers