1
容易的人。我目前正試圖添加2個音量滑塊到我現有的項目。我有兩個唱盤,deck1 & deck2,但我需要能夠單獨控制每個唱片的音量。如何添加2音量滑塊到我的MP3播放器as3
即時通訊相對較新的動作3所以即時通訊掙扎abit。誰能幫我請,這裏是我的代碼..
import flash.events.MouseEvent;
import flash.display.Sprite;
import flash.display.Graphics;
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.net.URLRequest;
import flash.utils.ByteArray;
import flash.text.TextField;
//variables
var mySound:Sound;
var myChannel:SoundChannel;
var nowPlaying:Boolean = false;
var nowPaused:Boolean = false;
var p:uint = 0;
var songfile:String;
var songtitle:String;
deck1_btn.addEventListener(MouseEvent.CLICK, deck1_data);
deck2_btn.addEventListener(MouseEvent.CLICK, deck2_data);
//song3_btn.addEventListener(MouseEvent.CLICK, song3_data);
stop_btn.addEventListener(MouseEvent.CLICK, stopSound);
stop2_btn.addEventListener(MouseEvent.CLICK, stopSound);
pause_btn.addEventListener(MouseEvent.CLICK, pauseSound);
function deck1_data(myEvent:MouseEvent):void {
songfile = "audio/desire.mp3";
songtitle = "Skeptical - Desire";
playSound(null);
}
function deck2_data(myEvent:MouseEvent):void {
songfile = "audio/tundra.mp3";
songtitle = "Skeptical - Tundra";
playSound(null);
}
//function song3_data(myEvent:MouseEvent):void {
songfile = "audio/always_be_mine.mp3";
songtitle = "Skeptical - Always Be Mine";
playSound(null);
function stopSound(myEvent:MouseEvent):void {
if (nowPlaying) {
myChannel.stop();
p = 0;
nowPlaying = false;
nowPaused = false;
}
}
function playSound(myEvent:Event):void {
mySound = new Sound;
mySound.load(new URLRequest(songfile));
title_txt.text = songtitle;
if (isPlaying) {
myChannel.stop();
myChannel = mySound.play(0);
} else {
myChannel = mySound.play(0);
nowPlaying = true;
}
}
function pauseSound(myEvent:MouseEvent):void {
if (isPlaying) {
p = Math.floor(myChannel.position);
myChannel.stop();
nowPlaying = false;
nowPaused = true;
} else if (nowPaused) {
myChannel = mySound.play(p);
nowPlaying = true;
nowPaused = false;
}
}
title_txt.text = "";
好吧,我已經試過這個,但它不知道我錯了。我會把這段代碼放在這裏:function playSound(myEvent:Event):void { mySound = new Sound; mySound.load(new URLRequest(songfile)); title_txt.text = songtitle; \t if(isPlaying){ \t \t myChannel.stop(); myChannel = mySound.play(0,1,new SoundTransform(myDeck1Volume)); \t} else { \t \t myChannel = mySound.play(0); \t \t nowPlaying = true; \t} } – nico
每次調用Sound.play時都應該使用SoundTransform –