How to play youtube videos on IOS using Actionscript 3

瘦欲@ 提交于 2020-01-05 10:16:09

问题


I am trying to fetch youtube playlist and play videos on IOS. My app works fine on Android and Flex simulators but does not work on IOS. Looks like there is a limitation on loading swfs in IOS here.

I am using as3-youtube-data-api for the purpose. Can anyone guide me on how can I embed or play youtube videos using as3 (Flash Builder 4.5) on IOS or is there any other way available?

Note: There is "Cisco Technical Support" app in app store, which plays youtube videos embedded in the app.

Update can VideoDisplay work, as I do not have mp4 for my playlists?

More Update

this is how at least m able to play youtube videos on IOS (read this), but again android gives me a black screen. Is there something I can do with this approach? Please give your suggestions. Thanks

var webView:StageWebView;
public function init():void
{
    NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;

    webView = new StageWebView(); 
    webView.viewPort = new Rectangle( 0, 35, this.stage.stageWidth, this.stage.stageHeight); 
    webView.stage = this.stage; 
    var htmlString:String = "<!DOCTYPE HTML>" + 
        "<html><body><script>" +
        "var tag = document.createElement('script');"+ 
        "tag.src = \"http://www.youtube.com/player_api\";"+ 
        "var firstScriptTag = document.getElementsByTagName('script')[0];"+ 
        "firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);"+
        "var player;"+

        "function onYouTubeIframeAPIReady() {"+
            "player = new YT.Player('player', {"+             
              "events: {"+
                "'onReady': onPlayerReady,"+
                "'onStateChange': onPlayerStateChange"+
              "}"+
            "});"+
        "}"+
        "function onPlayerReady(event) {"+
            "event.target.playVideo();"+
        "}"+
        "var done = false;"+
          "function onPlayerStateChange(event) {"+
            "if (event.data == YT.PlayerState.PLAYING && !done) {"+
              "setTimeout(stopVideo, 6000);"+
              "done = true;"+
            "}"+
          "}"+
          "function stopVideo() {"+
            "player.stopVideo();"+
        "}"+

        "</script>"+
        "<iframe id=\"player\" type=\"text/html\" width=\"100%\" height=\"400\" src=\"http://www.youtube.com/embed/g-YW2jkd-Ac\" frameborder=\"0\"></iframe>" + 
        "</body></html>"; 
    webView.loadString( htmlString );
    //webView.loadURL("http://www.youtube.com/embed/M7lc1UVf-VE");
}
public function dispose():void {
    try {
        webView.stage=null;
    } catch (e:Error) { trace("error")} 
}

Using Capabilities.os I can identify the OS and work my way through IOS and android.

Again, we cannot invoke javascript in IOS, so I am unable to stop the video.

Update

This is what I did for IOS. It gives in built player controls

public function initIOS():void
{
NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;

webView = new StageWebView();

webView.viewPort = new Rectangle( 0, 40, this.stage.stageWidth, this.stage.stageHeight-40);

webView.stage = this.stage; 
webView.loadURL("http://www.youtube.com/embed/"+data.videoId+"");
}

回答1:


As you've noted with the link you provided, you can't run actionscript swfs on iOS. It won't be long before there won't be any way to do it on Android, either. VideoDisplay also won't work because, well, it's actionscript.

To play Youtube videos on iOS, you can use (as the app you mentioned and other youtube-based apps on iOS do) the native Objective-C libraries, which will have full support for fetching playlists and playing videos; or could also try using the javascript client in a webapp.



来源:https://stackoverflow.com/questions/17297488/how-to-play-youtube-videos-on-ios-using-actionscript-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!