How to stream youtube video in corona.

I come from a Unity3D background, most of my programing experience is in c# and C++. I am trying to create an app that streams 2 youtube videos, one, then the other. How can I do this with corona? Some one pointed me to this sdk saying it would be simple. I see there is a template for streaming video but when I opended it it was just a black screen saying no video to display. Can someone assist me with this? I don’t need a full script(Although obviously that would be incredibly helpful) but Just a few lines. I looked at some documentation but nothing was explaining much. And the examples I pasted into the main.lua did absolutely nothing or had errors.

Corona SDK’s API calls do not support streaming services.  We support streaming if we can get a whole file to download (like a .mp4 or .mov file).  We will “stream” it as in start playing before the download completes, but it has to be a whole file.

For YouTube you might want to see what we did with the Business App Sample:  https://github.com/coronalabs/business-app-sample

Rob

Corona SDK’s API calls do not support streaming services.  We support streaming if we can get a whole file to download (like a .mp4 or .mov file).  We will “stream” it as in start playing before the download completes, but it has to be a whole file.

For YouTube you might want to see what we did with the Business App Sample:  https://github.com/coronalabs/business-app-sample

Rob

hi Rob,

the only movie I’ve been able to watch using the NewVideo template so far was from your site: http://www.coronalabs.com/video/bbb/BigBuckBunny_640x360.m4v

I thought it was because it was set up to be streaming… is it supposed to work with other m4v’s. I tried one of mine: http://www.onestopdesktop.com/images/DANGER.m4v and get nothing but Loading Video…

what am I doing wrong?

thanks!

It should play other .m4v files. There might be encoding issues. I know our older media.playVideo() has limits on bit rates, gotta be H.264, etc.

I tried to do a quick test but I don’t have a good way to get one of my .m4v files hosted at the moment or get it into the DocumentsDirectory.

Rob

can you try it with my remote .m4v file? I’m using the native.newVideo script.

I will likely get the same result as you, if the issue is encoding based.

Rob

so is there a link to the special encoding necessary? it’s just a movie. not sure how to encode it. I noticed the bunny example one was js driven but wasn’t sure how the scripting was internalized by the direct link to the movie.

and if I were uploading a movie from Corona SDK, how would this encoding be added to it from the code? I can’t really see it in the example scripts…

I repeated the test using my video that I copied to system.DocumentsDirectory and it played. So I tried your video and it did not initially play on my iPhone 6 (iOS 9.1). But there was an error on the console log.

You’re accessing an http:// address. In iOS 9, Apple has locked down access to non-secure websites. Are you building for IOS and is your device running iOS 9 or later?

If so please read:  https://coronalabs.com/blog/2015/09/17/about-app-transport-security-ats/

Rob

great pointer! I tried:

NSAppTransportSecurity =              {                 NSExceptionDomains =                  {                        ["onestopdesktop.com/] =                      {                         NSIncludesSubdomains = true,                         NSExceptionRequiresForwardSecrecy = false,                     },                 }, },

and more specifically:

NSAppTransportSecurity =              {                 NSExceptionDomains =                  {                        ["onestopdesktop.com/images/DANGER.mov“] =                      {                         NSIncludesSubdomains = true,                         NSExceptionRequiresForwardSecrecy = false,                     },                 }, },

and finally, the not recommended one that actually worked:

{ NSAppTransportSecurity =          {             NSAllowsArbitraryLoads = true          }, },

did I do something wrong with the first two approaches?

in addition, I added this to try and access youtube videos which didn’t work. one forum participant said it worked for him:

LSApplicationQueriesSchemes =              { "youtube"                        },

thanks again!

The domain name should just be the domain name, no other parts of the URL, for instance

["onestopdesktop.com/] =

should be

["onestopdesktop.com] =

But as long as you’re working.

Rob

this indeed worked! thanks!

NSAppTransportSecurity =          {             NSExceptionDomains =             {                ["onestopdesktop.com"] =                {                   NSIncludesSubdomains = true,                   NSThirdPartyExceptionAllowsInsecureHTTPLoads = true                },             },          },

what about the youtube issue? should we be able to access those videos through the newVideo player?

Youtube does a streaming protocol that we do not support. We have to have a physical file to download. The only way to show youtube videos is to use a native.newWebView().

You can vote for the feature request here:

http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback/suggestions/5486487–plugin-support-streaming-video-i-e-from-an-ip

It doesn’t have a lot of votes (I’m surprised actually). So the more votes the better.

Rob

dropped my max votes there! thanks for your help in this matter, Rob!

it was truly frustrating to not be able to see any other videos but Corona’s no matter which approach or sample code I tried! yes, to answer your earlier question, I am on 9.1 on an iPhone6.

tried webView. so far so good. need to figure out how to tweak the view, but it does play them! 

this provided a perfect YouTube view of one of my favorite video series:

local webView = native.newWebView( display.contentCenterX, 230, 570, 480 )

webView:request( “https://www.youtube.com/watch?v=F8OtE60T8yU” )

hi Rob,

the only movie I’ve been able to watch using the NewVideo template so far was from your site: http://www.coronalabs.com/video/bbb/BigBuckBunny_640x360.m4v

I thought it was because it was set up to be streaming… is it supposed to work with other m4v’s. I tried one of mine: http://www.onestopdesktop.com/images/DANGER.m4v and get nothing but Loading Video…

what am I doing wrong?

thanks!

It should play other .m4v files. There might be encoding issues. I know our older media.playVideo() has limits on bit rates, gotta be H.264, etc.

I tried to do a quick test but I don’t have a good way to get one of my .m4v files hosted at the moment or get it into the DocumentsDirectory.

Rob

can you try it with my remote .m4v file? I’m using the native.newVideo script.

I will likely get the same result as you, if the issue is encoding based.

Rob

so is there a link to the special encoding necessary? it’s just a movie. not sure how to encode it. I noticed the bunny example one was js driven but wasn’t sure how the scripting was internalized by the direct link to the movie.

and if I were uploading a movie from Corona SDK, how would this encoding be added to it from the code? I can’t really see it in the example scripts…