Flex 4 Spark 视频播放器如何从当前时间开始播放

发布于 2024-10-16 13:13:24 字数 2173 浏览 3 评论 0原文

有 4 个视频源,以便用户可以在视频源之间切换,视频进度相同。

我怎样才能实现这个? 函数 seek(time:duration):void 并没有真正起作用。 :-(

我使用的代码:

<?xml version="1.0" encoding="utf-8"?>

<fx:Script>
    <![CDATA[
        import mx.events.VideoEvent;

        import org.osmf.media.MediaPlayer;
        import org.osmf.video.CuePoint;

        protected function button1_clickHandler(event:MouseEvent):void
        {
            var playing:Boolean=VideoPlr.playing;
            var time:Number = VideoPlr.currentTime;
            VideoPlr.source = "http://helpexamples.com/flash/video/water.flv";
            // dosn't work this.VideoPlr.seek(VideoPlr.duration * time / 100);
            if(playing) VideoPlr.play();
        }


        protected function button2_clickHandler(event:MouseEvent):void
        {
            var playing:Boolean=VideoPlr.playing;
            var time:Number = VideoPlr.currentTime;
            VideoPlr.source = "http://helpexamples.com/flash/video/clouds.flv";
            // dosn't work this.VideoPlr.seek(VideoPlr.duration * time / 100);

            if(playing) VideoPlr.play();
        }


        protected function button3_clickHandler(event:MouseEvent):void
        {
            var playing:Boolean=VideoPlr.playing;
            var time:Number = VideoPlr.currentTime;
            VideoPlr.source = "http://helpexamples.com/flash/video/cuepoints.flv";
            // dosn't work this.VideoPlr.seek(VideoPlr.duration * time / 100);
            if(playing) VideoPlr.play();
        }


        protected function button4_clickHandler(event:MouseEvent):void
        {
            var playing:Boolean=VideoPlr.playing;
            var time:Number = VideoPlr.currentTime;
            //VideoPlr.source = "http://helpexamples.com/flash/video/cuepoints.flv";
            if(playing) VideoPlr.play();
        }

    ]]>
</fx:Script>
<s:VideoPlayer x="26" y="10" height="588" width="1081" autoPlay="false" 
               source="http://helpexamples.com/flash/video/water.flv" 
              id="VideoPlr" muted="false" pauseWhenHidden="true" 

在期待中感谢你

there are 4 Videosource so that the user can switch between it with the same progress of Video.

How can I implement this?
The funktion seek(time:duration):void dosn't really work. :-(

my Code that I use:

<?xml version="1.0" encoding="utf-8"?>

<fx:Script>
    <![CDATA[
        import mx.events.VideoEvent;

        import org.osmf.media.MediaPlayer;
        import org.osmf.video.CuePoint;

        protected function button1_clickHandler(event:MouseEvent):void
        {
            var playing:Boolean=VideoPlr.playing;
            var time:Number = VideoPlr.currentTime;
            VideoPlr.source = "http://helpexamples.com/flash/video/water.flv";
            // dosn't work this.VideoPlr.seek(VideoPlr.duration * time / 100);
            if(playing) VideoPlr.play();
        }


        protected function button2_clickHandler(event:MouseEvent):void
        {
            var playing:Boolean=VideoPlr.playing;
            var time:Number = VideoPlr.currentTime;
            VideoPlr.source = "http://helpexamples.com/flash/video/clouds.flv";
            // dosn't work this.VideoPlr.seek(VideoPlr.duration * time / 100);

            if(playing) VideoPlr.play();
        }


        protected function button3_clickHandler(event:MouseEvent):void
        {
            var playing:Boolean=VideoPlr.playing;
            var time:Number = VideoPlr.currentTime;
            VideoPlr.source = "http://helpexamples.com/flash/video/cuepoints.flv";
            // dosn't work this.VideoPlr.seek(VideoPlr.duration * time / 100);
            if(playing) VideoPlr.play();
        }


        protected function button4_clickHandler(event:MouseEvent):void
        {
            var playing:Boolean=VideoPlr.playing;
            var time:Number = VideoPlr.currentTime;
            //VideoPlr.source = "http://helpexamples.com/flash/video/cuepoints.flv";
            if(playing) VideoPlr.play();
        }

    ]]>
</fx:Script>
<s:VideoPlayer x="26" y="10" height="588" width="1081" autoPlay="false" 
               source="http://helpexamples.com/flash/video/water.flv" 
              id="VideoPlr" muted="false" pauseWhenHidden="true" 

thanking you in anticipation

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

み格子的夏天 2024-10-23 13:13:24

这是我的解决方案:

有四个文件可以在您的设计中切换。每个开关都会跳转到新源文件中的时间。

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
               creationComplete="createHandler();">
    <s:layout>
        <s:BasicLayout/>
    </s:layout>

    <fx:Script>
        <![CDATA[
            import flash.events.TimerEvent; //very important
            import flash.utils.Timer; //very important

            import flashx.textLayout.events.UpdateCompleteEvent;

            import mx.events.VideoEvent;

            import org.osmf.events.MediaElementEvent;
            import org.osmf.events.MediaPlayerStateChangeEvent;
            import org.osmf.media.MediaPlayer;
            import org.osmf.media.MediaPlayerState;


            private var time:Number=0;
            private var changed:Boolean = false;

            protected function normal_clickHandler(event:MouseEvent):void
            {
                ini();
                Text.text = "current Tume: "+time
                vid.source="1.flv"
            }
            protected function ini():void{
                if(vid.currentTime>0){
                    time = Math.round(vid.currentTime);
                    changed = true;
                    timer.reset();
                    timer.start();
                }
            }
            protected function nurhoer_clickHandler(event:MouseEvent):void
            {
                ini();
                vid.source="2.flv"
                Text.text = "current Tume: "+time;
            }


            protected function schwerh_clickHandler(event:MouseEvent):void
            {
                ini();
                Text.text = "current Tume: "+time;
                vid.source="3.flv"
            }

            protected function schwerhmH_clickHandler(event:MouseEvent):void
            {
                ini();
                Text.text = "current Tume: "+time;
                vid.source="4.flv"
            }
            protected var timer:flash.utils.Timer = new Timer(200,2);   
            private function createHandler():void
            {
                try{
                    timer.addEventListener(flash.events.TimerEvent.TIMER, repeat);
                    timer.addEventListener(flash.events.TimerEvent.TIMER_COMPLETE, repeat);
                    //console.text = "Events are loaded2!";
                }catch(exep){}
            }
            source="{source}" />
            private function repeat(event:flash.events.TimerEvent):void{
                if(!vid.playing){   
                try{

                        if(changed && Math.round(vid.currentTime)!= Math.round(time)){
//                          console.text = console.text +"\n"+"try to seek to: "+time;
                            vid.seek(time);
                            changed=false;
                        }else {
                            timer.reset();
                            timer.stop();
                            vid.play();
                        }
                    }catch (ex){}

                }
            }





        ]]>
    </fx:Script>

谢谢你的克制。

Here is my solution:

There are four files that can be switched in your deisgne. Each switch make jump to time in a new sourcefile.

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
               creationComplete="createHandler();">
    <s:layout>
        <s:BasicLayout/>
    </s:layout>

    <fx:Script>
        <![CDATA[
            import flash.events.TimerEvent; //very important
            import flash.utils.Timer; //very important

            import flashx.textLayout.events.UpdateCompleteEvent;

            import mx.events.VideoEvent;

            import org.osmf.events.MediaElementEvent;
            import org.osmf.events.MediaPlayerStateChangeEvent;
            import org.osmf.media.MediaPlayer;
            import org.osmf.media.MediaPlayerState;


            private var time:Number=0;
            private var changed:Boolean = false;

            protected function normal_clickHandler(event:MouseEvent):void
            {
                ini();
                Text.text = "current Tume: "+time
                vid.source="1.flv"
            }
            protected function ini():void{
                if(vid.currentTime>0){
                    time = Math.round(vid.currentTime);
                    changed = true;
                    timer.reset();
                    timer.start();
                }
            }
            protected function nurhoer_clickHandler(event:MouseEvent):void
            {
                ini();
                vid.source="2.flv"
                Text.text = "current Tume: "+time;
            }


            protected function schwerh_clickHandler(event:MouseEvent):void
            {
                ini();
                Text.text = "current Tume: "+time;
                vid.source="3.flv"
            }

            protected function schwerhmH_clickHandler(event:MouseEvent):void
            {
                ini();
                Text.text = "current Tume: "+time;
                vid.source="4.flv"
            }
            protected var timer:flash.utils.Timer = new Timer(200,2);   
            private function createHandler():void
            {
                try{
                    timer.addEventListener(flash.events.TimerEvent.TIMER, repeat);
                    timer.addEventListener(flash.events.TimerEvent.TIMER_COMPLETE, repeat);
                    //console.text = "Events are loaded2!";
                }catch(exep){}
            }
            source="{source}" />
            private function repeat(event:flash.events.TimerEvent):void{
                if(!vid.playing){   
                try{

                        if(changed && Math.round(vid.currentTime)!= Math.round(time)){
//                          console.text = console.text +"\n"+"try to seek to: "+time;
                            vid.seek(time);
                            changed=false;
                        }else {
                            timer.reset();
                            timer.stop();
                            vid.play();
                        }
                    }catch (ex){}

                }
            }





        ]]>
    </fx:Script>

thanks for your restraint.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文