如何PAN(改变声音平衡)flv文件的立体声通道

时间:2013-08-06 17:26:14

标签: actionscript-3 flex flex4.5

我希望能够播放flv文件的立体声通道。 表面上是这样我可以在播放flv时播放2种语言中的一种(右声道或左声道)。 我已经使用混音器“播放”了,并且无法使用flv。

我可以将soundMixer与videoPlayer一起使用吗?若然,有人可以更正我的(下面)代码吗?

TIA,     菲尔。

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

    <fx:Script>
        <![CDATA[

            protected function myVideo():void
            {               
                var soundMixer:SoundTransform = new SoundTransform();
                soundMixer.pan = 1;
                myVid.soundTransform = soundMixer;

                myVid.play();
            }

        ]]>
    </fx:Script>

    <s:VGroup width="100%" height="100%">
        <s:Button  id="playVideo" label="Video"  click="myVideo()"/>

        <s:VideoPlayer id="myVid" 
                       source="assets/caroLang.flv"
                       volume="1.0"
                       width="50%" height="50%"
                       autoPlay="false"
                       autoDisplayFirstFrame="true"
                       scaleMode="letterbox"
                       />
    </s:VGroup>
</s:View>

1 个答案:

答案 0 :(得分:0)

决定更改大头钉并使用多个mp3文件(每种语言一个)和视频播放,没有音频。

我正在测试selectLang变量并根据值播放不同的mp3文件。

点击视频按钮启动此过程,您可以停止,暂停或使用滑杆将视频和mp3移动到相应的同步位置。

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView"
    creationComplete="view1_creationCompleteHandler(event)">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<fx:Script>
    <![CDATA[
        import mx.core.SoundAsset;
        import mx.events.FlexEvent;

        import spark.components.mediaClasses.ScrubBar;

        import org.osmf.events.MediaPlayerStateChangeEvent;
        import org.osmf.events.TimeEvent;
        import org.osmf.traits.PlayState;

        private var seletedLang:String = "EN";

        public var loadedFile:File;
        public var channel:SoundChannel;
        public var songEN:SoundAsset;   
        public var songPT:SoundAsset;           
        private var currentVidTime:Number = 0;


        protected functio view1_creationCompleteHandler(event:FlexEvent):void
        {
            songEN = new SoundAsset();
            songEN.load(new URLRequest("assets/caro.mp3"));

            songPT = new SoundAsset();
            songPT.load(new URLRequest("assets/caro.mp3"));

            myVid.addEventListener(TimeEvent.CURRENT_TIME_CHANGE, scrubBarChange);
        }

        protected function scrubBarChange(event:TimeEvent):void
        {
            currentVidTime = event.time;
        }

        protected function myVideo():void
        {                                   
            if(seletedLang == "EN")
            {
                channel = songEN.play(currentVidTime*1000);
            }
            else
            {
                channel = songPT.play(currentVidTime*1000);
            }

            myVid.play();

        }

        protected function myVid_mediaPlayerStateChangeHandler(event:MediaPlayerStateChangeEvent):void
        {
            trace(event.state);

            if(event.state == "playing")
            {
                if(seletedLang == "EN")
                {
                    trace("****  " + currentVidTime);
                    if ( channel != null ) channel = songEN.play(currentVidTime*1000);
                }
                else if (seletedLang == "PT")
                {
                    if ( channel != null ) channel = songPT.play(currentVidTime*1000);
                }
            }
            else if(event.state == "paused")
            {

                if ( channel != null ) SoundMixer.stopAll();
            }
        }


    ]]>
</fx:Script>

<s:VGroup width="100%" height="100%">
    <s:Button  id="playVideo" label="Video"  click="myVideo()"/>

    <s:VideoPlayer id="myVid" 
                   source="assets/caroMute.flv"
                   volume="0.0"
                   width="50%" height="50%"
                   autoPlay="false"
                   autoDisplayFirstFrame="true"
                   scaleMode="letterbox"
                   mediaPlayerStateChange="myVid_mediaPlayerStateChangeHandler(event)"
                   />
</s:VGroup>
 </s:View>