Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble with multiple songs in Flex - AS3
    primarykey
    data
    text
    <p>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.</p> <p>Here is the code I am using:</p> <pre><code> // 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; } } </code></pre> <p>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.</p> <p>Any ideas?</p> <p>Thanks.</p> <p>EDIT:</p> <p>I should also mention the error I am getting with the current code:</p> <p>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]</p> <p>Cheers</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload