Play Video on Android

I have built an App and it is working on Android but I am trying to play a local .MP4 or .M4V video file using Corona. I put the video file directly on device and it plays fine. I am using PAVTUBE and I have tried the H.264 and MPEG-4 formats per documentation…

It does not play using Corona code… please help:

function playMovie()
media.playVideo(“test.mp4”, true, onVideoComplete )
end

local onVideoComplete = function(event)
print( “video session ended” )
end
[import]uid: 10965 topic_id: 3608 reply_id: 303608[/import]

Android requires a bit of special handling. See this thread:
http://developer.anscamobile.com/forum/2010/07/24/pathforfile-android
and our documentation here:
http://developer.anscamobile.com/content/system-os#system.ResourceDirectory
[import]uid: 54 topic_id: 3608 reply_id: 10966[/import]

Thanks for quick reply —

Here is update:

1] I have same code working fine on the iPhone, iTouch, iPad

2] I have tried the following with Android:

  • “test.mp4”
  • system.pathForFile(“test.mp4”, system.ResourceDirectory)
  • media.playVideo(“http://127.0.0.1/test.mp4”, media.RemoteSource, true)

None work — so, I checked what was in the .APK file

And the .MP4 is not being included in the .APK file when creating an Android build

Please help get this fixed. Let me know. Thanks again. [import]uid: 10965 topic_id: 3608 reply_id: 11026[/import]

This is the feature of android itself. You can only play .mp4 videos if streamed from web or the file is in sd card. [import]uid: 48512 topic_id: 3608 reply_id: 30112[/import]

I have been using an elonex etouch 10" and can play mp4 files directly from the nand directory.

Do you mean corona can only play mp4 files that are streamed.

[import]uid: 4585 topic_id: 3608 reply_id: 30523[/import]

I have been testing the streaming video sample application and replaced the existing path with:
media.playVideo( “http://80.5.54.130/http2/apps/videos/mp4 rotated/warden.mp4”, media.RemoteSource, true )

If I play this file from the a memory stick or internal memory it runs okay.
If I point to this in the browser I get the error that I need a memory card to run the file.

When I run the sample app it simply says cannot play the format.

Cheers
SteveW [import]uid: 4585 topic_id: 3608 reply_id: 30685[/import]

Hi,

Local video (video files packaged in the APK) now plays on Android device builds with Corona SDK daily build 336 and later (developer.anscamobile.com/downloads/daily-builds). There is a remaining usability issue when returning/exiting from the video player back to your app (case 4523) that we hope to fix shortly.

Tim [import]uid: 8196 topic_id: 3608 reply_id: 30711[/import]

Any news on case 4523?

media.playVideo is not very usefull if we can’t return to our apps after playing video. [import]uid: 45699 topic_id: 3608 reply_id: 43164[/import]

>>There is a remaining usability issue when returning/exiting from the video player back to your app (case 4523) that we hope to fix shortly.<<

Has this been resolved? I tested this and it does not return to the app on playback. [import]uid: 8780 topic_id: 3608 reply_id: 45329[/import]

also one more thing when i try to play video on android it is left aligned with lots of space (black screen) in right in the iphones it is center aligned with equal black screen at both side how can i put that at center aligned for android and after completing video screen goes black completely even i am using timer to jump at next scene i figure if i lock device and unlock device again it is on next screen (not solution actually) works fine on idevices

the video is at the starting of game just to intro story

let me know how to fix this

:slight_smile: [import]uid: 12482 topic_id: 3608 reply_id: 45355[/import]

Everyone,

Tomorrow’s daily build (avilable to subscribers) contains several fixes for the Android video player. Particularly:

  • Now supports landscape view and change of orientation.
  • Automatically returns to the app when the video has ended.
  • Now supports the device’s back button to return to the app during playback.
  • Video is now centered horizontally onscreen instead of left justified.

It isn’t quite perfect just yet. It still has the following issues that we need to work on:

  • The video player’s controls cannot be hidden.
  • Video playback resets when changing the orientation of the device.
  • Ability to lock the orientation to landscape or portrait?
    That said, this is a big improvement and we wanted to make sure to get it in your hands. And yes, we’re listening. :slight_smile: [import]uid: 32256 topic_id: 3608 reply_id: 45565[/import]

happy to hear

:slight_smile: [import]uid: 12482 topic_id: 3608 reply_id: 45567[/import]

Hmmm… our main server did not produce a daily build. I’ll have to check the server room and make sure that the hamsters are still running on their wheels. [import]uid: 32256 topic_id: 3608 reply_id: 45652[/import]

Can you provide sample code to play video on the Android for the latest build? Does it only work with streaming? For example:

local gURL = “Words.mp4”
system.openURL(gURL)

or can we use:

media.playVideo(“test.mp4”, true, onVideoComplete )

Thanks.

Jane [import]uid: 8780 topic_id: 3608 reply_id: 48378[/import]

Hello Jane,

See the sample app “media/StreamingVideo” that is included with the Corona SDK to see how to stream video from the Internet. Alternatively, you can play a local video file that is included with your app and play it as follows…

media.playVideo(“MyVideo.mp4”)
[import]uid: 32256 topic_id: 3608 reply_id: 48395[/import]

I just want to verify that this is for the latest Corona SDK that fixes the Android video playback problems regarding the back button and returning to the previous screen after the video plays? [import]uid: 8780 topic_id: 3608 reply_id: 48403[/import]

Jane,

Yes! There have been many video player fixes on Android in this release. The video player now automatically closes when the video finishes. You can also press the Android back button to exit the video player. Only a couple issues remain such as video playback resets when changing the orientation of the device. See my post up above (#10) for more details. [import]uid: 32256 topic_id: 3608 reply_id: 48410[/import]

Checking in to see if some of these other issues will be resolved soon?

  • The video player’s controls cannot be hidden.
  • Video playback resets when changing the orientation of the device.
  • Ability to lock the orientation to landscape or portrait? [import]uid: 91662 topic_id: 3608 reply_id: 56794[/import]

valmih,

We haven’t addressed these issues yet, but they are on our wish list.

Regarding locking the video player’s orientation, as a simple fix, how would you like it if we have the video player’s orientation match the orientation of your Corona app? That would be a simple fix to make; at least starting off. For example, if your app is landscape only, then the video player will be landscape. If your app is portrait, then the video player will be portrait. [import]uid: 32256 topic_id: 3608 reply_id: 56955[/import]

Hi Joshua

That would be a perfect fix for the projects i’m working on right now.
It would be so great if you could do that!!! [import]uid: 13632 topic_id: 3608 reply_id: 56965[/import]