0

我正在尝试创建一个迷你媒体播放器 AIR 应用程序,它允许用户查看通过外部 XML 文件加载的视频、图像和歌曲,同时还允许用户浏览他们自己的文件并通过查看器播放任何媒体。截至目前,当单击图像缩略图时,我可以让视频停止播放,但是当新视频开始时,我无法让任何声音停止播放。事实上,我什至无法改变歌曲。一旦你点击一首歌曲,它就会播放并且不会停止,并且它不能被另一首歌曲取代。

这是我正在使用的代码:


 // for audio
            public var _channel:SoundChannel = new SoundChannel();
            public var _sound:Sound = new Sound();



            public function getDetails():void{
                    var mySelectedItem:File = tree.selectedItem as File;

                    var type:String;
                    type = mySelectedItem.url.substr(mySelectedItem.url.lastIndexOf("."))

                    switch (type)
                    {
                        case ".mp3":
                            _sound.load(new URLRequest(mySelectedItem.url));
                            _channel = _sound.play();
                            if (mainVideo.source == null){
                                // do nothing
                            } else {
                                mainVideo.pause();
                            }
                        break;

                        case ".jpg":
                        mainImage.source = mySelectedItem.url;
                        mainVideo.visible = false;
                        mainImage.visible = true;
                            if (mainVideo.source == null){
                                // do nothing
                            } else {
                                mainVideo.pause();
                            }
                        break;

                        case ".png":
                        mainImage.source = mySelectedItem.url;
                        mainVideo.visible = false;
                        mainImage.visible = true;
                        if (mainVideo.source == null){
                                // do nothing
                            } else {
                                mainVideo.pause();
                            }
                        break;

                        case ".flv":
                        mainVideo.source = mySelectedItem.url;
                        mainImage.visible = false;
                        mainVideo.visible = true;
                        mainVideo.play();
                        _channel.stop();
                        break;

                        case ".avi":
                        mainVideo.source = mySelectedItem.url;
                        mainImage.visible = false;
                        mainVideo.visible = true;
                        mainVideo.play();
                        _channel.stop();
                        break;

                        case ".mov":
                        mainVideo.source = mySelectedItem.url;
                        mainImage.visible = false;
                        mainVideo.visible = true;
                        mainVideo.play();
                        _channel.stop();
                        break;
                    }
                }

                public function getWebDetails(e:Event):void{
                    switch (e.currentTarget.getRepeaterItem().type as String)

                    {
                        //mp3s
                        case "song":
                        var isPlaying:Boolean;
                        isPlaying = false;
                        if (!isPlaying){
                            _sound.load(new URLRequest(e.currentTarget.getRepeaterItem().url));
                            _channel = _sound.play();
                            isPlaying = true;
                        } else if (isPlaying == true) {
                            _channel.stop();
                            isPlaying = false;
                        }
                        if (mainVideo.source == null){
                            // do nothing
                        } else {
                            mainVideo.pause();
                            mainVideo.visible = false;
                            mainImage.visible = true;
                        }
                        break;

                        //images
                        case "image":
                        mainImage.source = e.currentTarget.getRepeaterItem().url;
                        mainVideo.visible = false;
                        mainImage.visible = true;
                        if (mainVideo.source == null){
                            // do nothing
                        } else {
                            mainVideo.stop();
                        }
                        break;

                        case "video":
                        mainVideo.source = e.currentTarget.getRepeaterItem().url;
                        mainImage.visible = false;
                        mainVideo.visible = true;
                        mainVideo.play();
                        break;

                    }

                }

我尝试创建一个布尔值来控制音乐何时播放,认为它能够处理歌曲应该改变的事实,但我错了。

有任何想法吗?

谢谢。

编辑:

我还应该提到我在当前代码中遇到的错误:

错误:错误 #2037:函数调用顺序不正确,或者之前的调用不成功。在 flash.media::Sound/_load() 在 flash.media::Sound/load() 在 brightEyes_mediaPlayer/getWebDetails()[C:\Users\Graham\Documents\y02s01\AVIS317 - FLEX\brightEyes\src\brightEyes_mediaPlayer。 mxml:122] 在 brightEyes_mediaPlayer/___brightEyes_mediaPlayer_Image3_click()[C:\Users\Graham\Documents\y02s01\AVIS317 - FLEX\brightEyes\src\brightEyes_mediaPlayer.mxml:187]

干杯

4

1 回答 1

0

You know, if this was a linux related question you'd get a RTFM as an answer. But instead I'll just redirect you to this little piece of important information. And then give you the following advice: always look in the language reference first when you encounter problems.

于 2009-12-21T09:17:27.773 回答