Reputation: 358
I'm trying to live stream from youtube to android application. But whenever I stop my live stream, the URL for the stream changes and I need to constantly change the video code in my android-app and push the update. Is there any other way to live stream my content to the Android app other than youtube. Here is the code for my youtube player in android app:
youTubePlayerView = (YouTubePlayerView)findViewById(R.id.youtube_player_view);
onInitializedListener = new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.play();
youTubePlayer.setFullscreen(true);
youTubePlayer.loadVideo("video-code");
}
Every time I need to change the video code to a new code in the application whenever I start a new stream. Is there a way to automatically get the new video code or is there any other way I can live stream the content to my mobile. I'm using Open Broadcaster to stream it on youtube.
Upvotes: 0
Views: 878
Reputation: 358
Since nobody answered my question, I'll answer it on my own.
Instead of using youtube API, we can use a webview
. No instead of using a video-code to stream youtube live, we can use channelID
in the youtube link to permanently embed the live stream to the webview
.
Here is the code for it:
public class WebViewPlayer extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_view_player);
String frameVideo = "<html><body>Youtube video .. <br> <iframe width=\"400\" height=\"290\" src=\"https://www.youtube.com/embed/live_stream?channel=YOUR_CHANNEL_ID\" frameborder=\"0\" allowfullscreen=\"true\"></iframe></body></html>";
WebView webView = (WebView)findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadData(frameVideo, "text/html", "utf-8");
}
}
Upvotes: 3