Resizing and Controlling media.playVideo()

Ah so i got confused about the meaning of ‘streaming’. Thanks piotrz.

I’ll use media.playVideo() instead.

How to remove the player object? Or like @bcournoyer stated above, media.playVideo() will remove itself.

If so, when will that happen? When the video end? On application exit?

And about

Do you mean we can control video player on ios?

But beforehand, do you mean ‘control’ like resizing, rotating, or moving position?

Sorry my english is uh… kinda limited, so i don’t get the ‘as such’ part…

Hi guys, sorry to bump this back to the top again but I’m still unsure on something with this.

If I want to provide an “exit” button to allow users to quit watching a video half way through and return to the app, how do I go about this? I can’t find any way to do it when using media.playVideo()

Is there a way to achieve this? The native player doesn’t seem to have a quit button.

Thanks,

Ian

On iOS there is button to close video in native controls. On android you use hardware back button.

If it will help there are some facts.

When on ios and android video ends then onComplete function is triggered. When you open video on ios, application is still running in the background. When you close it using “ready” button (I’m not sure about lablel but it should be blue button in top left corner) also onComplete function is triggered.

On android when you open player then it will take a fraction of second but android will suspend app and app will pause executing code.

So if you write

-- 1st media.playVideo( .... ) print("playing") -- 2nd local function doSomething() print("playing delayed") end media.playVideo(...) timer.performWithDelay(250, doSomething)

In first case, “playing” will be printed instantly beacause it takes some little time to open player. However, in second case “playing delayed” won’t be printed until you close video. 

I must emphassise that if you interupt video on android (close it by hardware return button) then onComplete won’t trigger.

So if I’m on iOs then I use onComplete and if I’am on android then I use the same function but as delayed by timer.

Thanks for the info. Much appreciated.

I was ideally looking for a solution that allowed me to play the video at a custom size in a custom popup with a close button but from the looks of it that’s impossible on Android so will go with the above in the default media player.

I hadn’t understood that the close button wouldn’t appear in the simulator (it just displays the video players with no close button).

Fine on device though.

Thanks!

Ian

So using media.playVideo() give us no access to size and position. Is there a way to at keep the video’s original ratio?

I have a portrait-oriented app and the video width take as much as the screen width, but the height is just not right. The video got stretched downward.

How about streaming video? Anyone has experience with this?

Can i stream a video, say from **utube, than play it inside the app?

I tried media.playVideo() and add media.RemoteSource, but i got “could not load video” or such message.

Or should i just use native.newWebView() to open the web page?

Yes, you can play video from Internet be it must be streamed video. Youtube do not stream video (read about streaming).

On Android you cannot control video as such with media.playVideo. what it does is Corona passes video to native android player and suspends. When you close player then Corona resumes.

So Corona do not have control over native player.

Ah so i got confused about the meaning of ‘streaming’. Thanks piotrz.

I’ll use media.playVideo() instead.

How to remove the player object? Or like @bcournoyer stated above, media.playVideo() will remove itself.

If so, when will that happen? When the video end? On application exit?

And about

Do you mean we can control video player on ios?

But beforehand, do you mean ‘control’ like resizing, rotating, or moving position?

Sorry my english is uh… kinda limited, so i don’t get the ‘as such’ part…

Hi, if i have understood i can’t play youtube videos by media.playVideo(),alright?? 

Correct you cannot play youTube videos with media.playVideo().  You have to use a webView to play youTube videos.

Hi, if i have understood i can’t play youtube videos by media.playVideo(),alright?? 

Correct you cannot play youTube videos with media.playVideo().  You have to use a webView to play youTube videos.

Is that Still not possible today? 

Yes, this is still true.

Rob

So what is the best way of displaying a video? A webview of youtube? I need users to be able to access movie trailers…

What is the best way to display a video?  Well that’s tough to answer.   Where is the video?  What format is it in?  Is it coming from a streaming service or do you have the entire video file?

Corona SDK’s built in video features are designed to work where you get a physical file.  That is, I can play a video from a web server if I’m getting a .mp4 file.  But if it’s a streaming service like YouTube, you don’t download a file you use a player to just stream data you will throw away when done.  Corona SDK doesn’t have facilities to access data from that kind of service.

You can look at the code in our Business App Sample ( where we get a list of YouTube videos and then play the video in a webView.

Rob

Thanks a lot for your quick answer, I will look in to that! 

I might just download the videos and host them myself…

One more problem: I do not understand why I get this error:“Attempt to index local ‘image’ (a nil value)”

local image = display.loadRemoteImage( “http://2.bp.blogspot.com/-LDaA7cP9MmA/Tddgg2e-HcI/AAAAAAAABoQ/xHH5Wau_V00/s1600/hello.png”, “GET”, networkListener, “helloCopy.png”, system.TemporaryDirectory, display.contentCenterX, display.contentCenterY)
image.x = -100 + image.x

Is there another way to move the image?

display.loadRemoteImage() doesn’t return a display object like the other API calls.  Instead it will call your “networkListener” function when the image finishes downloading.  At that point, the display object will be in “event.target” and you can move it inside the listener.  At the point you call display.loadRemoteImage() it returns immediately and image doesn’t exist at that point.

Rob

Is there any way to create a normal display object from the loaded image? Sorry if this is a stupid question, I am learning to use corona…

local image

local function networkListener( event )

     – you should of course test to make sure you really downloaded the image her, I’m not going to include that code.

     image = event.target

     image.x = -100 + image.x

end

display.loadRemoteImage( “http://2.bp.blogspot.com/-LDaA7cP9MmA/Tddgg2e-HcI/AAAAAAAABoQ/xHH5Wau_V00/s1600/hello.png”, “GET”, networkListener, “helloCopy.png”, system.TemporaryDirectory, display.contentCenterX, display.contentCenterY)

Yes but I still will not be able to acess the image out of the networkListenerfunction right?