Ciao a tutti, ho il seguente problema. Ho realizzato un player audio dove dovrebbero essere ascoltati brani mp3 provenienti da server RTMP. Ho utilizzato seguente codice:
//Importiamo gli eventi necessari
import flash.events.Event;
import flash.events.MouseEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
var isPlaying:Boolean = new Boolean();
var pausePosition:Number = new Number();
var nc:NetConnection = new NetConnection();
//nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
nc.connect("rtmp://sonymusicfs.fplive.net/sonymuscceg/level3/upload/mps/catalog_11/6a/af/d7/susanboylesilentnight.MP3");
var ns:NetStream=new NetStream(nc);
var audio:Video
myVideo.attachNetStream(ns);
//ns.play("susanboylesilentnight");
var soundClip:Sound=new Sound();
//Creiamo un oggetto SoundChannel
var sndChannel:SoundChannel = new SoundChannel();
//Richiamiamo il file audio esterno con URLRequest
//soundClip.load(new URLRequest("http://sonymusicfs.fplive.net/sonymuscceg/level3/upload/mps/catalog_11/6a/af/d7/susanboylesilentnight.MP3"));
//Creiamo un evento Listener per rimanere aggiornati sulla fine del suono
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
function asyncErrorHandler(event:AsyncErrorEvent):void
{
trace(event.text);
}
nc.client=this;
//ns.play("susanboylesilentnight");
soundClip.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
controller.addEventListener(MouseEvent.MOUSE_DOWN, btnPressController, false, 0, true);
stop_btn.addEventListener(MouseEvent.MOUSE_DOWN, btnPressStop, false, 0, true);
function onComplete(evt:Event):void
{
//Riporduci il brano
sndChannel=soundClip.play();
isPlaying=true;
}
function btnPressController(evt:MouseEvent):void
{
switch (isPlaying)
{
case true :
controller.gotoAndStop(2);
pausePosition=sndChannel.position;
sndChannel.stop();
isPlaying=false;
break;
case false :
controller.gotoAndStop(1);
sndChannel=soundClip.play(pausePosition);
isPlaying=true;
break;
}
}
function btnPressStop(evt:MouseEvent):void
{
pausePosition=0;
sndChannel.stop();
controller.gotoAndStop(2);
isPlaying=false;
}
L'errore che mi da è il seguente:
1061: Call to a possibly undefined method attachNetStream through a reference with static type flash.media:Sound. soundClip.attachNetStream(ns);
Mi sapete dire in cosa sbaglio? o se conoscete un modo migliore in AS 3 per richiamare un file da RTMP?
Le molte ricerche fatto sono state vane visto che si parla più di video.
grazie in anticipo per il vostro aiuto.
MICK

Rispondi quotando