views:

154

answers:

1

Hello all,

I am trying to create a mini media player AIR app that allows users to view videos, images, and songs loaded in through an external XML file, while also allowing the user to browse through their own files and play any media through the viewer. As of right now, I can get videos to stop playing when an image thumb is clicked, but I can't get any sound to stop playing when a new video starts. In fact, I can't even get songs to change. Once you click on one song, it plays and doesn't stop, and it can't be replaced by another song.

Here is the code I am using:


 // 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;

         }

        }

I have tried creating a Boolean to control when music is playing, figuring that it would be able to handle the fact that the song should change, but I was wrong on that one.

Any ideas?

Thanks.

EDIT:

I should also mention the error I am getting with the current code:

Error: Error #2037: Functions called in incorrect sequence, or earlier call was unsuccessful. at flash.media::Sound/_load() at flash.media::Sound/load() at brightEyes_mediaPlayer/getWebDetails()[C:\Users\Graham\Documents\y02s01\AVIS317 - FLEX\brightEyes\src\brightEyes_mediaPlayer.mxml:122] at brightEyes_mediaPlayer/___brightEyes_mediaPlayer_Image3_click()[C:\Users\Graham\Documents\y02s01\AVIS317 - FLEX\brightEyes\src\brightEyes_mediaPlayer.mxml:187]

Cheers

A: 

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.

bug-a-lot