views:

1390

answers:

1

Hello,
I am working on a very simple player written in MXML+ActionScript whose functions are exported to be called by a simple Javascript in an HTML page.

Both codes are provided below.

For the mp3 "path" all is working perfectly for playing, pausing, resuming and stopping...
For the m4a "path", starting is working well, stopping too but pausing is bugging
After having started an m4a, when I clicked on "pause" it rightly stops the stream.
But when I am clicking back on the button to resume, it does not start again at all

Does anybody know where is the problem?
Is the fact that I'm using just a simple Apache Web Server and not a real Flash Streaming server the reason why it does not work?

Thanks in advance for your help.

The MXML+ActionScript 3

   <?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="callBacks()">
    <mx:Script>
     <![CDATA[
       import flash.events.Event;
       import flash.media.Sound;
       import flash.net.URLRequest;
       import flash.external.ExternalInterface;
       public var playingChannel:SoundChannel;
       public var playingSound:Sound;
       public var pausePosition:int=0;
       public var playingUrl:String="";
       public var codec:String="";
       public var playingStream:NetStream;

       public function playSound(url:String):void {
        if (playingUrl!=url) {
         if (playingUrl!="") {
          stopSound();
         }
         playingUrl=url;
         codec=playingUrl.substring(playingUrl.length-3);
         if (codec=="m4a") {
          var mySound:SoundTransform;
          var connect_nc:NetConnection = new NetConnection();
          connect_nc.connect(null);
          playingStream=new NetStream(connect_nc);
          playingStream.play(url);
         }
         else if (codec=="mp3") {
          playingSound=new Sound(new URLRequest(url));
          playingChannel=playingSound.play();
         }
        }
        else {
         if (codec=="m4a")
          playingStream.pause();
         else
          playingChannel=playingSound.play(pausePosition);
        }
       }
       public function pauseSound():void {
        if (codec=="m4a")
         playingStream.pause();
        else if (codec=="mp3") {
         pausePosition=playingChannel.position;
         playingChannel.stop();
        }
       }
       public function stopSound():void {
        if (codec=="m4a")
         playingStream.close();
        else if (codec=="mp3") {
         pausePosition=0;
         playingChannel.stop();
        }
        playingUrl="";
       }
       public function callBacks():void {
        ExternalInterface.addCallback("play",playSound);
        ExternalInterface.addCallback("pause",pauseSound);
        ExternalInterface.addCallback("stop",stopSound);
       }
     ]]>
    </mx:Script> 
</mx:Application>



and the basic HTML+Javascript

   <html>
<head>
<script src='jquery.js'></script>
<script>
    function play() {
     //alert('clicked');
     var url=$("#url").val();
     var k=url.substring(url.length-3);
     fromFlash('testFlash').play(url);
     var b=document.getElementById('pp');
     b.setAttribute('src','pauseButton.jpg');
     b.setAttribute('onclick','pause()');
    }
    function pause() {
     fromFlash('testFlash').pause();
     var b=document.getElementById('pp');
     b.setAttribute('src','playButton.jpg');
     b.setAttribute('onclick','play()');
    }
    function stop() {
     fromFlash('testFlash').stop();
     var b=document.getElementById('pp');
     b.setAttribute('src','playButton.jpg');
     b.setAttribute('onclick','play()');
    }
    function fromFlash(movieName) {
     var isIE = navigator.appName.indexOf("Microsoft") != -1;
     return (isIE) ? window[movieName] : document[movieName];
    }
</script>
</head>
<body>
<object id="testFlash" width="0" height="0">
    <param name="movie" value="player.swf"></param>
    <param name="allowFullScreen" value="true"></param>
    <embed name="testFlash" src="player.swf" type="application/x-shockwave-flash" allowfullscreen="true" width="0" height="0">
    </embed>
</object>
<input id="url"/>
<span><img id="pp" src="playButton.jpg" onclick="play()"/></span>
<span><img src="stopButton.jpg" onclick="stop()"/></span>
</body>
</html>
+2  A: 

I believe you want to call pause() again to resume, not play(). According to the NetStream documentation, the pause() method is used to both pause and resume.

Herms