- stopBtn - кнопка "стоп"
- playBtn - кнопка "плей"
- st01 - "радиостанция 1"
- st02 - "радиостанция 2"
- st03 - "радиостанция 3"
а при нажатии stopBtn любой поток прекращался.
Пусть немного "каша" получилась, но наверное смысл ясен...
Код: Выделить всё
function radio1Click(e:MouseEvent):void { // если играет какой-то поток, то останавливаем if (music != null){ music.stop(); } //запускаем новый поток var url = "http://URL1"; var request:URLRequest=new URLRequest(url+'?'+Math.random()); var sound = new Sound(); sound.load(request); var music=sound.play();}
Код: Выделить всё
var snd:Sound = new Sound();var channel:SoundChannel = new SoundChannel();var req:URLRequest = new URLRequest();var context:SoundLoaderContext = new SoundLoaderContext(3000,false); /*-------------------Слушатели-------------------*/radio1.addEventListener(MouseEvent.CLICK, play1);radio2.addEventListener(MouseEvent.CLICK, play2);radio3.addEventListener(MouseEvent.CLICK, play3);radioStop.addEventListener(MouseEvent.CLICK, radioSt);//radioPlay.addEventListener(MouseEvent.CLICK, radioPl); /*-------------------Радиостанция 01-------------------*/function play1(e:MouseEvent):void{ playSound("http://maximum-128.app1848482.moeradio.ru:10000/Maximum-128"); name_txt.text="Максимум"} /*-------------------Радиостанция 02-------------------*/function play2(e:MouseEvent):void{ playSound("http://nrj-128.app1848482.moeradio.ru:10000/NRJ-128"); name_txt.text="NRJ"} /*-------------------Радиостанция 03-------------------*/function play3(e:MouseEvent):void{ playSound("http://hit_fm-128.app1848482.moeradio.ru:10000/Hit_FM-128"); name_txt.text="Хит ФМ"} /*-------------------Кнопка "Стоп"-------------------*/function radioSt(e:MouseEvent):void{ channel.stop();} /*-------------------Кнопка "Плей"-------------------function radioPl(e:MouseEvent):void{ }*/ /*-------------------Функция воспроизведения-------------------*/function playSound(station:String){ channel.stop(); req.url = station; snd = new Sound(); snd.load(req, context); channel = snd.play();}
Код: Выделить всё
var play_url:String; // глобальная переменная function play1(e:MouseEvent):void{ play_url = 'http://maximum-128.app1848482.moeradio.ru:10000/Maximum-128'; playSound(play_url); name_txt.text="Максимум"}
Telv писал(а):а в кнопке "плей" что тогда писать?
Код: Выделить всё
{ playSound(play_url); // адрес будет взят из глобальной переменной play_url}