Youtube video keeps playing until app is closed - codenameone

Some questions for playing youtube videos in webBrowser component.
I played youtube video in webBrowser component. But it keeps playing when the form is backed as well. It only stops playing when the app is removed. I tried webBrowser.stop() and webBrowser.destroy() method etc in the back command but with no success.
String getVideoUrl = "https://www.youtube.com/embed/" + videoId + "?autoplay=1";
WebBrowser player = new WebBrowser();
player.setURL(getVideoUrl);
f.addComponent(BorderLayout.CENTER, player);
However webBrowser.reload() solves the problem on android phones but not on Android Tablets.
While viewing the video, if the mobile is set to sleep by the user, the display goes out while watching the video. So how to disable the sleep mode?
Mobile screen display out problem.
When the video completes, the youtube video gives video link of the related videos & they can be played too, how can I disable that. I don't want to make other videos play from the app
The video doesn't play in android icecream sandwich and below.

Try: webBrowser.setPage("<html><head></head><body></body></html>", null);
You can use Display.getInstance().setScreenSaverEnabled(false);.
That's a setting on youtube for embedded links. You can select to disallow it.
That's a limitation of the html embed code from google. Not much we can do here.

Related

How to render the playback rate for a YouTube video player

I am working on a personal YouTube video player project and am looking at cookpete's react-player. Here is the link to the file I am referencing: https://github.com/cookpete/react-player/blob/master/src/demo/App.js.
Here's the actual player as well: https://cookpete.com/react-player/.
I'm trying to figure out how to render the playback rate on the page. cookpete's includes three buttons (1x, 1.5x, 2x) that changes the playback rate displayed, but if you use a YouTube link as the URL and change the speed with the built-in YouTube bar, the speed rendered doesn't change.
Would it be possible to render the current playback rate on the page that updates with the built-in bar? I believe there a function in the YouTube iFrame API (player.getPlaybackRate()), but since I am not using iFrame, how would I integrate this (maybe event.target.getPlaybackRate())? I've also seen some things about React refs but not sure how I'd use here.
Thank you for your time. I am new to React/API calls, so any help is greatly appreciated.

Is there any way to stream music in the background with Ionic framework?

I'm developing an Android app using Ionic for music streaming, like a personal Spotify. I can easily play an audio file using Streaming Media plugin, but it seems that this plugin was made for video purposes, because it always brings the player to the front in fullscreen, so you can't navigate through the app while the music is playing, you also can't lock your screen or the playback is stopped.
Is there any way to stream music in the background? Like when I tap the song I want to play, it just starts playing without bringing in another screen? (like you can easily do in AndroidStudio with MediaPlayer). I've search it anywhere for the past week and I just can't find any solution.
I realized Background-Audio in my ionic2/3 Project with
cordova-plugin-media 3.0.1 "Media"
cordova-plugin-music-controls 2.1.4 "MusicControls"
and to workaround some issues on ios I need to add this plugin also
nl.kingsquare.cordova.background-audio 1.0.1 "background-audio"

AngularJS: Embedding Youtube videos in iframe does not work on Android Chrome

I'm developing a web application with AngularJS and I'm using a directive for embedding responsive Youtube videos called youtubeResponsive which allows to embed videos in an iframe with a video id as source parameter.
It all works perfectly on desktop browsers, in fact I also managed to embed a playlist and play it in a loop.
The problem I'm having is now on Chrome Android, on a Nexus 5 device (running Lollipop latest update) the video embedded is not showing and instead I can see a notification of a download going on. Every time I refresh I see the download process restarting but no video is showing. If I click on the download notification to see the file nothing happens.
Of course my aim is to display the video also on mobile with autoplay and loop active.
The output which I can see inspecting the page on mobile using USB debugging (chrome://inspect/#devices)
<iframe id="ytplayer" type="text/html" width="100%" height="202.5" ng-src="http://www.youtube.com/v/ZhfUv0spHCY?version=3&autoplay=1&loop=1&controls=0&showinfo=0&rel=0&wmode=opaque" frameborder="0" allowfullscreen="" video-slug="ZhfUv0spHCY" class="ng-isolate-scope" src="http://www.youtube.com/v/ZhfUv0spHCY?version=3&autoplay=1&loop=1&controls=0&showinfo=0&rel=0&wmode=opaque"></iframe>
I don't see any error on mobile except the same warning I can see on desktop which apparently is not blocking the video from playing at least there.
Resource interpreted as Document but transferred with MIME type application/x-shockwave-flash:
"https://www.youtube.com/v/ZhfUv0spHCY?version=3&autoplay=1&loop=1&controls=0&showinfo=0&rel=0&wmode=opaque".
Anyone experienced the same issue on Android Chrome or on other mobile devices and OS ?
I haven't started testing on AOSP or iOS yet but already on Chrome the issue is quite concerning. Let me know if anyone managed to fix it.
You're specifically requesting the old Flash player widget and not allowing it to upgrade to HTML5, which is required now for mobile support of any kind. You should switch to the YouTube Player API, which requires a few extra lines of code to implement but will work almost anywhere and give you a lot of event data back about videos playing, etc.
https://developers.google.com/youtube/iframe_api_reference
You can still use an IFRAME with this technique, although consider this directive which appears to support the current API:
https://github.com/brandly/angular-youtube-embed

Codename one media player pause and play issue

I am facing an issue with playing video files in Cn1.
The video starts playing on play, pauses on pause, but does not resume back on play.
This also happens with the kitchen sink app.
Device: Motox
Further, if I am using the native player mode, the video play and pause works fine, but the video does not launch properly in full screen. It gets aligned to the left of the screen and the application is seen in the background in the rest of the screen.
The application is in landscape mode.
This is a regression in Codename One's Android media player. It should be fixed for the next server update.

How to play youtube vidoes in silverlight(in browser)?

I want to develop an silverlight application which plays youtube videos. I dont want to let users install my silverlight application on thri PCs, so I would need to play the videos in browser. Is there anyway we can achieve this?
Silverlight 4 comes with a new WebBrowser control which lets you display HTML content (e.g. an iframe with youtube in it). Unfortunately, that control will work in Out-Of-Browser mode only. So if you don't want users to install your app on their PCs, that won't be an option for you.
So the only ways I see to work around that problem are
A) Open a popup (new browser window) which shows youtube content.
B) Use JavaScript to open a new div/iframe on top of your Silverlight app which shows youtube. You will have to enable the so-called windowless mode for your Silverlight app then (otherwise, you won't be able to display any kind of HTML on top of your app).
Cheers, Alex

Resources