ユーザーが外部 XML ファイルを介して読み込まれたビデオ、画像、および曲を表示できるようにするミニ メディア プレーヤー AIR アプリを作成しようとしています。現時点では、画像のサムがクリックされたときにビデオの再生を停止することはできますが、新しいビデオが開始されたときにサウンドの再生を停止することはできません。実際、曲を変えることさえできません。1 つの曲をクリックすると、再生されて停止せず、別の曲に置き換えることはできません。
私が使用しているコードは次のとおりです。
// 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] で
乾杯