【问题标题】:How to display custom player controls on youtube chromeless player using Flash builder 4.6?如何使用 Flash builder 4.6 在 youtube 无铬播放器上显示自定义播放器控件?
【发布时间】:2013-04-11 14:42:04
【问题描述】:

我有一个 View 组件,它使用“http://www.youtube.com/apiplayer?version=3&modestbranding=1”url 初始化 youtube cloud api 并全屏播放视频。它在s:actionContent 下有播放、暂停和进度条,但我试图在无铬播放器本身的顶部放置“倒带”、“播放/暂停”、“前进”和交互式进度条(带有图像按钮的透明弹出窗口同样),如下图所示。

初始化 youtube api 的我的视图组件没有任何项目。 (删除s:actionContent 以尝试弹出窗口)

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" title="YoutubeVideoPlay" viewActivate="init()" >
    <fx:Script source="YoutubePlayer.as"/>
    <fx:Script>
        <![CDATA[
            //navigator.addEventListener(TouchEvent.TOUCH_BEGIN,showPlayerControl);     How to add a event listener on the youtube player?
            public function showPlayerControl():void{
                PopUpManager.addPopUp(PlayerControls,player);
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
</s:View>

当用户点击正在播放的视频时,需要帮助这个弹出管理器出现在无铬播放器的顶部。

<s:Panel xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" width="400" height="300">
    <fx:Script source="../YoutubePlayer.as"/>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        global
        {
            modal-transparency: 0.0;
            modal-transparency-color: white;
            modal-transparency-blur: 0;
        }
    </fx:Style>
    <fx:Script>
        <![CDATA[               
            import mx.managers.PopUpManager;
            /*[Bindable][Embed(source="view/assets/images/play32.png")]
            public static var iconPlay : Class;*/
            [Bindable][Embed(source="view/assets/images/pause32.png")]
            public static var iconPause : Class;
            [Bindable][Embed(source="view/assets/images/forward32.png")]
            public static var iconForward : Class;
            [Bindable][Embed(source="view/assets/images/rewind32.png")]
            public static var iconRewind : Class;               
            //addEventListener(FlexMouseEvent.MOUSE_DOWN_OUTSIDE,removePlayerControls);
            /*private function removePlayerControls(event:FlexMouseEvent):void {
            PopUpManager.removePopUp(this);
            }*/             
            public function closeAndBackup():void {
                dispose();
                navigator.popView();                                
            }
            public function initAndPlay():void {                
                player.playVideo();

            }               
            private var _duration:String = "";

            [Bindable]
            public function get duration():String {
                return _duration;
            }               
            public function set duration(val:String):void {
                _duration = val;

            }
            protected function ytVideoSlider_changeHandler(event:Event):void
            {
                // TODO Auto-generated method stub
                trace(event.currentTarget.value);
                player.seekTo(event.currentTarget.value,true);              
            }
        ]]>     
    </fx:Script>
    <s:VGroup>
        <s:HGroup>
            <s:layout>
                <s:HorizontalLayout paddingTop="10" paddingLeft="10"/>
            </s:layout>
            <s:HSlider id="ytVideoSlider" 
                       liveDragging="true"
                       dataTipPrecision="1"
                       maximum="{duration}"
                       change="ytVideoSlider_changeHandler(event)"/>
            <s:Label text="{Math.round(ytVideoSlider.value)}"/>
        </s:HGroup>
        <s:Button icon="{iconRewind}" click="player.playVideo()"/>
        <s:Button icon="{iconPause}" click="player.pauseVideo()"/>
        <s:Button icon="{iconForward}" click="closeAndBackup()"/>
    </s:VGroup>
</s:Panel>

任何帮助将不胜感激。 :)

我刚刚开始使用 Flash Builder 的 spark 组件,如果我的问题太蹩脚,请原谅我。

或者是否有任何链接/教程可用于将播放器控件放置在无铬 youtube 播放器之上?

更新:我能够解决我的问题,并且也提供了我的解决方案

【问题讨论】:

  • 特别是因为您对问题提出了赏金,您应该对答案发表评论,以澄清他们缺少的内容。
  • @MarkFox:实际上,在这个问题上悬赏之后,我就能解决我的问题。这类似于科林给出的答案。我也会发布我的答案。
  • 经典问题解决难题。提出问题可以帮助我始终自我解决问题。
  • @MarkFox:是的 :) 我添加了我的解决方案。

标签: youtube flex4 youtube-api flash-builder flex4.6


【解决方案1】:

您应该能够为整个视图添加点击侦听器。虽然我以前从未使用过这个 API,但我想它看起来像这样:

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
xmlns:s="library://ns.adobe.com/flex/spark" title="YoutubeVideoPlay"
viewActivate="init()" click="showPlayerControl()">

<fx:Script source="YoutubePlayer.as"/>
<fx:Script>
    <![CDATA[
        public function showPlayerControl():void{
            PopUpManager.addPopUp(PlayerControls,player);
        }
    ]]>
</fx:Script>
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

【讨论】:

    【解决方案2】:

    所以你快到了。您需要记住的是,YouTube 播放器有自己的交互,例如,当用户单击视频时,它通常会暂停/恢复。现在您可以通过在视频顶部放置一个不可见的Sprite 来解决此问题,因为这将允许您捕捉用户的鼠标移动和点击。

    唯一的问题是当前的自动播放状态;目前(以及我猜未来)自动播放不算作视频的观看次数。用户需要按下 YouTube 视频上的播放按钮才能真正将其计为观看次数。

    所以我所做的只是在播放开始后添加这个不可见的Sprite。然后,当用户单击您的隐形Sprite 时,您还可以聪明地向播放器本身发送暂停/恢复事件。

    关于您所追求的 UI 组件:它们很容易组合在一起,您可以随时获取标准 UI Flash/Flex 组件并将它们连接到播放器 API(我看到您已经开始了) ;不过,在脑海中构思设计而不是在代码中一遍又一遍地勾勒出 UI 总是一个好主意。

    作为脚注:随时欢迎您使用我在 github 上的 YouTube 播放器中间件类:https://github.com/ahmednuaman/AS3/blob/master/com/firestartermedia/lib/as3/display/component/video/YouTubePlayerAS3.as

    【讨论】:

      【解决方案3】:

      我的问题的解决方案

      我有一个PlaylistsView.mxml,它有一个包含所有视频的列表。单击后,它会推送一个名为 YtPlayView.mxml 的新视图

      <!--YtPlayView.mxml-->  
      <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
          xmlns:s="library://ns.adobe.com/flex/spark"
          xmlns:popup="views.popup.*"
          title="{data.title}" viewActivate="init()" viewDeactivate="deactivateYoutubePlayer()">
          <fx:Script source="ytfeeds/YoutubePlayer.as"/>
          <fx:Script>
              <![CDATA[
                  public function deactivateYoutubePlayer():void{
                      PopUpManager.removePopUp(ytcPopup);
                      dispose();
                  }
              ]]>
          </fx:Script>
      </s:View>
      

      YoutubePlayer.asonPlayerReady(event:Event)我添加了一个鼠标点击事件监听器player.addEventListener(MouseEvent.CLICK,showPlayerControl);

          <!--YoutubePlayer.as contents-->
      public function showPlayerControl(event:MouseEvent):void{
          ytcPopup=new PlayerControls();
          ytcPopup.player=player;
          ytcPopup.duration=data.duration;                
          ytcPopup.currentPosition="00:00:00";        
          ytcPopup.open(this,true);
          ytcPopup.width = this.stage.width;
          ytcPopup.setStyle("modalTransparency",0);
          ytcPopup.setStyle("modalTransparencyBlur",3);
          ytcPopup.setStyle("modalTransparencyColor", "#ff0000");
          if(ytcPopup.player.getPlayerState()==1){        
              ytcPopup.playPauseBtn.setStyle("icon",ytcPopup.iconPause);
          }
          else if(ytcPopup.player.getPlayerState()==2){       
              ytcPopup.playPauseBtn.setStyle("icon",ytcPopup.iconPlay);
          }
          ytcPopup.y = this.stage.height-195;
          PopUpManager.bringToFront(ytcPopup);        
          if(player.getCurrentTime()!=0)
              ytcPopup.ytVideoSlider.value=player.getCurrentTime();       
      }
      

      这给了我类似下面的内容(这是一个纵向视图,在横向视图中它位于视频的顶部)

      如果有人想要更多源代码或帮助,我很乐意提供帮助 :) 只需发表评论即可。

      【讨论】:

        猜你喜欢
        • 2011-05-05
        • 2010-12-09
        • 1970-01-01
        • 2011-09-29
        • 2012-10-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多