×
A new build of Corona SDK is now available to subscribers. Not a subscriber? Subscribe now.
CoronaSDK 2012.821 | Released: 23 May 2012, 2:01am | What's New | Download Now

media.playVideo()

Description:

Plays the video at the specified path (both local and remote) in a device-specific popup Video media player.

During video playback, the media player interface takes over. If showControls is true, then the user can adjust playback, e.g. start, stop, seek, etc. Pass a listener to get notified when the video has ended. Note this function is asynchronous: any code that follows will be executed. After that, the application code will continue to run on iOS devices, but on Android devices the application will be suspended until the video playback is complete.

Supported video formats are platform- and version-dependent. The iPhone video player supports playback of movie files with the .mov, .mp4, .m4v, and .3gp filename extensions and using the following compression standards:

  • H.264 Baseline Profile Level 3.0 video, up to 640 x 480 at 30 fps. Note: B frames are not supported in the Baseline profile.
  • MPEG-4 Part 2 video (Simple Profile)
Syntax:

media.playVideo( path [, baseSource ], showControls, listener )

Example:

local onComplete = function(event)
   print( "video session ended" )
end
media.playVideo( "Movie.m4v", true, onComplete )

Parameters:

path
The local filename or a remote URL for the video.

baseSource
Optional parameter that controls how the local filename path is interpreted. It can either be one of the system-defined directory constants, or media.RemoteSource (use this to access video on a remote server).

showControls
If true, then the user can adjust playback, e.g. start, stop, seek, etc.

listener
Listener to notify when the video has ended. The listener can be either a function listener or a table listener. If listener is a table, it must have a completion method. The event dispatched to the listener will be a completion event.

Returns:

Nothing.

Remarks:

This API is not available in Corona Simulator.

Supported on operating systems and platforms for build numbers shown:
  • Mac OS X:
    --
  • Windows:
    --
  • iOS:
    Corona SDK 2.0
  • Android:
    Corona SDK 2.0

Replies

webfraggle
User offline. Last seen 1 year 22 weeks ago. Offline
Joined: 12 Dec 2010

Is it possible to show videos inside the applikation. Like an intro video or a trailer before the next level.

Thanks webfraggle

neilirani's picture
neilirani
User offline. Last seen 2 weeks 1 day ago. Offline
Joined: 2 Jan 2011

I ran with this a .m4v file i created in iMovie, but the simulator just flashes up the Corona logo thing then goes blank.

I'm new to Corona and am getting frustrated that I can't even get a simple thing to work!!

Grateful for any help.

snarla's picture
snarla
User offline. Last seen 16 weeks 1 day ago. Offline
Alumni
Joined: 25 May 2010

Video playback is currently only supported in device builds, not in Corona Simulator.

chris.slee5's picture
chris.slee5
User offline. Last seen 34 weeks 19 min ago. Offline
Joined: 11 Feb 2011

Is it possible (or planned) to play a youtube vid through media.playVideo? Something like

media.playVideo( "http://m.youtube.com/#/watch?xl=xl_blazer&v=NEjq0VwGrNc", media.RemoteSource, true )

mrvaibhavpanchal
User offline. Last seen 45 weeks 2 hours ago. Offline
Joined: 1 Mar 2011

I am trying to make an custom interactive video app.

Following are my queries:

1.1) Is There a work around to put some invisible buttons on top of video when playing which responds to touch event?

1.2) Any work around to have other event listeners such as OnPause?

2) Can I can skin the standard video controls with custom images.

3) I guess this is more of a feature request. To be able to play portion of video. Eg. media.play("myvideo.mp4", "0:05", "1:05", true). It plays video from 5th second till 1 minute 5 seconds

Sorry about flooding questions in single post. =)

Tom
User offline. Last seen 11 hours 20 sec ago. Offline
Staff
Joined: 13 Jul 2010

The current video play is pretty basic and doesn't have any options to do what you need.

I would suggest posting your feature enhancements on the Forum so others can read and comment. That is one way that we gauge what users want in the product.

Thanks,
Tom

Ninja Pig Studios's picture
Ninja Pig Studios
User offline. Last seen 10 hours 28 min ago. Offline
Joined: 26 Jan 2011

Does this work with Android? What is the file format that the video would need to saved in? Does it need to be in the rez stated for it to work?

Ninja Pig Studios's picture
Ninja Pig Studios
User offline. Last seen 10 hours 28 min ago. Offline
Joined: 26 Jan 2011

Ok there is a problem with Android with this code. On all devices I have experimented with this code makes the video play vertical in a super small window and not horizontal like it should be. How do I fix this?

Jefemcownage
User offline. Last seen 19 weeks 3 days ago. Offline
Joined: 29 Aug 2010

I want to create a seamless transition between a still and video on the ipad, but currently the play video call clears the screen and shows black for like 1 second before playing. Is there a way to work around this?

Sassa's picture
Sassa
User offline. Last seen 6 weeks 6 days ago. Offline
Joined: 17 Jul 2011

Hey man..
Did you get anyway to play videos or trailers inside the application?

ty

cflowers
User offline. Last seen 33 weeks 5 days ago. Offline
Joined: 27 Sep 2011

If I build the streaming video example this works fine ...

1
media.playVideo( "http://www.anscamobile.com/video/Corona-iPhone.m4v", media.RemoteSource, true )

... but if I put your "Corona-iPhone.m4v" on our server it fails.
In fact ANY video I put on our server fails. Thoughts?!

I need to stream 30MB-50MB videos. Please help. Thanks!

cflowers
User offline. Last seen 33 weeks 5 days ago. Offline
Joined: 27 Sep 2011

Resolved. Needed MIME type added to the server. :/

underwaterdiver's picture
underwaterdiver
User offline. Last seen 8 weeks 23 hours ago. Offline
Joined: 28 Oct 2011

How do I find the code documentation for cases?

Example below is only a summary and I've searched and searched and don't find the cases explained:

Fixed media.playVideo() to support landscape, back button, and to back out when video ends. (571) - cases 2374, 4523

Any help is appreciated.

Thanks,
Richard

jaypozo
User offline. Last seen 3 days 20 hours ago. Offline
Joined: 8 Sep 2011

I'm using the complete event to switch scenes using storyboards. I get this error: "CGImageDestinationAddImage image parameter is nil" on a scene change and I've read that it may be related to not cleaning up any event listeners properly. Is there a way to cleanup this listener? Like media.removeListeners? Thanks.

Dan Pereira
User offline. Last seen 18 weeks 6 days ago. Offline
Joined: 12 Oct 2010

I'm playing m4a files from my server using media.playVideo(). It works and is the only way a can see to do audio streaming from the web, but the background of the player has a >>Q<< "quicktime" sort of watermark on it. Is there any way to get rid of the watermark, or display a custom image instead of the watermark? Maybe layer a display object over the video player?? (I need to try that.)

jagregori
User offline. Last seen 5 days 5 hours ago. Offline
Joined: 24 Mar 2011

I'm using playVideo to access radio streams. The stream should be played even if you turn off the screen, but pressing on/off button turns off the stream. Can I prevent this? I can't do it.

jagregori
User offline. Last seen 5 days 5 hours ago. Offline
Joined: 24 Mar 2011

Problem solved with webpopup.

topnotch374
User offline. Last seen 1 week 3 days ago. Offline
Joined: 1 Feb 2012

Hi cflowers,

Was just wondering if you can help me out. I'm very new to this sdk and just wanted to get some guidelines on streaming videos.

Basically I wanted to stream videos posted in youtube.com and vimeo.com on my app. Any suggestion on doing this?

Thanks much,