【问题标题】:Embedding youtube into flash with actionscript 3使用 actionscript 3 将 youtube 嵌入到 flash
【发布时间】:2013-07-31 08:25:23
【问题描述】:

我正在努力将 youtube 视频嵌入到我的 flash 项目中,经过数小时的努力寻找工作教程和研究谷歌提供的 api,我无法得到任何工作。 我想要一个可以从 youtube 播放列表中播放的播放器,因为目标是展示乐队的现场表演,但我不知道如何让它从地面开始!

如果有人能提供帮助,将不胜感激。

谢谢! :)

【问题讨论】:

    标签: actionscript-3 flash youtube embed


    【解决方案1】:
    import flash.system.Security;
    
    Security.allowDomain( '*' );
    Security.allowInsecureDomain( '*' );
    
    var vPlayer:Object;
    var playerLoader:Loader;
    
    function loadVideo():void
    {
        playerLoader = new Loader();
    
        // next line loads a youtube player with no UI
        playerLoader.load( new URLRequest( 'http://www.youtube.com/apiplayer?version=3' ) );
    
        // wait for it to load
        playerLoader.contentLoaderInfo.addEventListener( Event.INIT, onLoaderInit );
    }
    
    function onLoaderInit( evt:Event ):void
    {
        // 'vPlayer_container' is a movieclip on stage that you need to create to hold the youtube player.
        // add your youtube Loader, ( which is actually the player ), to vPlayer_container's display list.
        vPlayer_container.addChild(playerLoader);
    
        // set the vPlayer variable to be the loaded youtube player
        vPlayer = playerLoader.content;
    
        // wait for it to be ready
        vPlayer.addEventListener( 'onReady', onPlayerReady );
    }
    
    function onPlayerReady( evt:Event ):void
    {
        vPlayer.removeEventListener( 'onReady', onPlayerReady );
    
        // set listener for onComplete and play/pause events
        vPlayer.addEventListener( 'onStateChange', onPlayerStateChange );
    
        // mute it on start if you want
        vPlayer.mute();
    
        // set size of video screen
        vPlayer.setSize( 392,220 );
    
        // now load your youtube video in your new youtube player
        // get this video number off the url to your youtube video
        vPlayer.loadVideoById( 'GEghz32qhiA', 0 );
    }
    
    function onPlayerStateChange( evt:Event ):void
    {
        // if video is over
        if( Object(evt).data == 0 )
        {
            //do something when video is over
        }
    }
    
    // other player commands available - you need to make your own buttons for these
    // vPlayer.mute();
    // vPlayer.unMute();
    // vPlayer.pauseVideo();
    // vPlayer.playVideo();
    
    // to start the whole process, call loadVideo();
    

    【讨论】:

    • 感谢您的回答,我已将代码放入其中,但不幸的是它在程序末尾显示了意外的右大括号,当我摆脱那个大括号时,它说程序意外结束,我我错过了什么?谢谢!
    • 可能来自 onPlayerChange() 方法。我编辑它。用新方法试试。此外,当我从内存中编写代码时,此代码可能无法正常运行,这只是为了让您入门。你需要的所有东西都在那里。如果你足够了解 as3 语法,你应该能够从那里拼凑起来。
    猜你喜欢
    • 1970-01-01
    • 2013-05-07
    • 2012-11-12
    • 1970-01-01
    • 1970-01-01
    • 2017-04-26
    • 2012-01-14
    • 1970-01-01
    • 2015-12-19
    相关资源
    最近更新 更多