media.playVideo() with Android

Hi,

I am working on an application for android. I used media.playvideo() with my project. when we call media.playvideo() then video start playing . If same time, before video completion , we press back button then we found a black screen and  I can not read this event on keyevent also [Runtime:addEventListener( “key”, onKeyEvent )]. Please give  solution if anybody faced same problem ever.

Hi @abhishekkumar.jain,

Have you checked that there’s not some other error occurring? The “black screen” may be the app halting because of some error, not necessarily related to the video or key press.

Please read this tutorial on Android debugging and respond back with an error message, if you can locate one:

http://www.coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

Best regards,

Brent Sorrentino

Hi @abhishekkumar.jain,

Have you checked that there’s not some other error occurring? The “black screen” may be the app halting because of some error, not necessarily related to the video or key press.

Please read this tutorial on Android debugging and respond back with an error message, if you can locate one:

http://www.coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

Best regards,

Brent Sorrentino

@Brent

I also think there is a problem with media.playVideo on android.

The video ended listener in media.playVideo is never fired when you press the backbutton on android.

This only happens on android devices on other platforms it works fine.

I’m using media.playVideo (and native.newVideo), and when the video goes full screen and I hit back on my droid (old nexus 7, Jelly Bean), it stops/closes the vid and returns to my app (which looks perfect at that point).

However, as ojnab says, it looks like the media.playVideo completion listener never gets fired off if you hit the back key. (Perhaps this is the original source of the problem on this thread).

NOTE: If someone from coronaLabs is going to go in there and tweak some video code, could REALLY use a little more data on videos exposed… Just having the width/height of the video would be VERY helpful – as it is now, the app can’t tell if the video was recorded portrait or landscape when loading the file so they can look like @#$@# because they video object isn’t initialized in the right orientation.

Also – .3gp files recorded on droid, any droid, will NOT play back in the corona app. If I email them to my ipod, I can play them from there… But they will NOT play back in media playVideo, or with native.NewVideo… No go on iOS. the SDK will load the video… And I can see that it has a length ( video.totalTime > 0 )… But once you call the video:load() function, the video listener function NEVER gets called with the “ready” event. Trying to launch the 3gp file fullscreen with media.playVideo flashes the IOS player up for a moment, but it just quits and immediately returns to the app…

Bottom line: video (3gp files) recorded with corona on android will not playback on ios.

yes same here it returns to the app when pressing the back button, but the listener is not fired.

It is a problem if you for example want to fade your app to black before showing video ( to do a smooth transition between

the app and the video player ). If the completion listener doesn’t fire, the app doesn’t get notified when it should fade back to normal.

@Brent

I also think there is a problem with media.playVideo on android.

The video ended listener in media.playVideo is never fired when you press the backbutton on android.

This only happens on android devices on other platforms it works fine.

I’m using media.playVideo (and native.newVideo), and when the video goes full screen and I hit back on my droid (old nexus 7, Jelly Bean), it stops/closes the vid and returns to my app (which looks perfect at that point).

However, as ojnab says, it looks like the media.playVideo completion listener never gets fired off if you hit the back key. (Perhaps this is the original source of the problem on this thread).

NOTE: If someone from coronaLabs is going to go in there and tweak some video code, could REALLY use a little more data on videos exposed… Just having the width/height of the video would be VERY helpful – as it is now, the app can’t tell if the video was recorded portrait or landscape when loading the file so they can look like @#$@# because they video object isn’t initialized in the right orientation.

Also – .3gp files recorded on droid, any droid, will NOT play back in the corona app. If I email them to my ipod, I can play them from there… But they will NOT play back in media playVideo, or with native.NewVideo… No go on iOS. the SDK will load the video… And I can see that it has a length ( video.totalTime > 0 )… But once you call the video:load() function, the video listener function NEVER gets called with the “ready” event. Trying to launch the 3gp file fullscreen with media.playVideo flashes the IOS player up for a moment, but it just quits and immediately returns to the app…

Bottom line: video (3gp files) recorded with corona on android will not playback on ios.

yes same here it returns to the app when pressing the back button, but the listener is not fired.

It is a problem if you for example want to fade your app to black before showing video ( to do a smooth transition between

the app and the video player ). If the completion listener doesn’t fire, the app doesn’t get notified when it should fade back to normal.

I can confirm this, this is a bug. onComplete listener is not fired if user closes video with back button. Not fixed yet on latest release.

EDIT: Okay people i found a workaround! Using the “system” event listener with Runtime, we can know when a user has finished watching a video by pressing the back button.

Read more about it here:

http://www.coronalabs.com/blog/2012/07/17/using-system-events-to-save-app-state/

Use:

local function onSystemEvent(event)     if event.type == "applicationResume" then         onVideoComplete()     end end

Make sure to remove the event listener after this, and of course, check if the platformName is Android:

platformName = system.getInfo("platformName") if platformName == "Android" then Runtime:addEventListener( "system", onSystemEvent ) end

I can confirm this, this is a bug. onComplete listener is not fired if user closes video with back button. Not fixed yet on latest release.

EDIT: Okay people i found a workaround! Using the “system” event listener with Runtime, we can know when a user has finished watching a video by pressing the back button.

Read more about it here:

http://www.coronalabs.com/blog/2012/07/17/using-system-events-to-save-app-state/

Use:

local function onSystemEvent(event)     if event.type == "applicationResume" then         onVideoComplete()     end end

Make sure to remove the event listener after this, and of course, check if the platformName is Android:

platformName = system.getInfo("platformName") if platformName == "Android" then Runtime:addEventListener( "system", onSystemEvent ) end

Pressing back during the video activity will fire a completion event as of build 2148.

Pressing back during the video activity will fire a completion event as of build 2148.

I am using media.playVideo() in splash screen for Android App. When splash screen video is playing, If same time we lock the Device; Application will go in susnpend mode. When we unlock phone and start application, splash video is not playing that time. What to do?  

I am using media.playVideo() in splash screen for Android App. When splash screen video is playing, If same time we lock the Device; Application will go in susnpend mode. When we unlock phone and start application, splash video is not playing that time. What to do?