11 Replies Latest reply on Sep 7, 2011 10:27 PM by markerline

    newbie: flash audio not playing

    nobood09 Level 1

      I am brand new to flash and AS3, and everything else code related. I've built a simple file with text and audio. The audio is an external file, and it plays with a mouse click. Everything tests fine in flash. I also placed the file in Dreamweaver and previewed in a browser - that's working. But... I've now uploaded the file to a live site. The text shows up but it doesn't play. Where should I look for the problem?

        • 1. Re: newbie: flash audio not playing
          markerline Level 4

          post your AS3 code and someone will be able to inspect it for you for possible errors--server-s

          ide speaking.

          • 2. Re: newbie: flash audio not playing
            nobood09 Level 1

            This is the code I'm using. thanks.

             

            stage.addEventListener(MouseEvent.CLICK, fl_ClickToPlayStopSound);

             

            var fl_SC:SoundChannel;

             

            function fl_ClickToPlayStopSound(evt:MouseEvent):void

            {

            if(fl_ToPlay)

            {

            var s:Sound = new Sound(new URLRequest("audio/L57_passage_p1_1.mp3"));

            fl_SC = s.play();

            }

            else

            {

            fl_SC.stop();

            }

            fl_ToPlay = !fl_ToPlay;

            }

            • 3. Re: newbie: flash audio not playing
              markerline Level 4

              firstly I would add the event listener to the button that's activating playback.  Not to the stage unless you want any portion of the stage to activate playback.

               

              I must assume that fl_toPlay is the button?

               

              also, are you nesting swf's?  Or is this file your only file that is referencing the audio directly on the server.  Check to make sure that your audio is named properly on your server and that your directory structure is proper.

               

              I can't think of anything off hand besides what I mentioned.  Are you using a local server or a server located on the internet?  If it's a server on your local network it may not work properly.  I have had this happen when trying to play FLV's over my local network.  On the internet it works fine. 

               

              What device(s) are you using to test your playback functionality?  If your mp3 is large it may not cache properly on Flash-enabled smartphones or tablet devices.

              • 4. Re: newbie: flash audio not playing
                nobood09 Level 1

                any portion of the stage activates playback, and that's ok as I'm just using it at this point to read paragraphs of text. I'd like to figure out how to click sentence by sentence and highlight the text eventually, but this is my starting point.

                 

                I am not nesting swf's. this is the only file that is referencing the audio directly on the server.  I'll triple check directory link, but I think its ok.

                 

                I'm using an internet server when I have the problem. The file plays fine on my local machine.

                 

                I'm just testing on Mac and PC. No mobile or tablet at this point.

                • 5. Re: newbie: flash audio not playing
                  markerline Level 4

                  As far as per-sentence audio cues are concerned you could use a similar technique that is used by Flash Video wrapper components that use cuepoints to go to a particular video section or trigger a stage event at that particular cue point.  At least I'm guessing you could.

                   

                  You could also use a combination of substring conditional statements that search for a particular combination of substrings within the given text but you would have to feed your text into the actionscript to do so.  Simply having audio wouldn't be an effective way to do it because voice recognition is very very complex.  And I haven't come across any voice recognition in Flash although someone has probably done it.  But you would feed the matching text that is based on the audio into a searchable string.  You could probably use XML or something also to check for text phrases and trigger highlighting.  I'm brainstorming.

                   

                  I will have to use your code and test it out on my end to see if I can get it to play, if in fact your directory structure works and your server is up and running properly and playing back the audio normally.

                   

                  Can you test something for me?

                   

                  Can you code the following in Dreamweaver?:

                   

                  <html>

                  <head>

                  <title>test audio</title>

                  </head>

                  <body>

                  <a href="[the path and name of your mp3]">my audio link</a>

                  </body>

                  </html>

                   

                  See if that webpage plays back the href link within the browser.  You can use Google's browser to test since it usually automatically detects mp3's.

                  • 6. Re: newbie: flash audio not playing
                    nobood09 Level 1

                    thanks for the brainstoming. I was thinking along the lines of cue points, but it will take me some time to wrap my head around that and then generate the code.

                     

                    As for the Dreamweaver test, yes. it works with the code you supplied.

                    • 7. Re: newbie: flash audio not playing
                      markerline Level 4

                      Okay.

                       

                      In the line that you are defining your SoundChannel variable you have to declare it as such:

                       

                      var mySoundChannelVar:SoundChannel=new SoundChannel();

                       

                      you can keep the same variable name you have but you have to not only type the variable as a soundchannel but also make sure you define it with the new keyword as an instance.

                       

                      Also, I would if I were using Booleans define the variable as a Boolean as such:

                       

                      var myPlaybackBoolean:Boolean;

                       

                      I also experienced some lag time before the audio started playing when I used my own audio mp3.  You have to note that the audio file is data that progressively downloads and in many cases it would be good practice to use a preloader to show that the audio is loading and the user doesn't click away from the page to a different website.

                       

                      Now, granted I could not upload to my http server and test but given this is not video it should work with the extra parameters I included in the code in this post.  Try it and report back.  I am off to sleep.

                      • 8. Re: newbie: flash audio not playing
                        nobood09 Level 1

                        thank you so much for your help. I will definitely give this a try and let

                        you know. G'night.

                        • 9. Re: newbie: flash audio not playing
                          adninjastrator Level 4

                          As for using "Flash Video wrapper components", since the .flv is just a container file (it can contain a video file & an audio file, just video, or just audio), you could use it to contain just an audio file, the mp3, and then have the full interactivity available with cue points, popping text up at various points in the audio file, (event type cue point), or navigate to various sections of the file (navigation type cue point).

                          old tutorial but good for background:

                          http://layersmagazine.com/flash-video-cue-points-with-adobe-flash-professional-8.html

                          http://www.quip.net/blog/2007/flash/how-to-use-flash-video-cue-points

                          But as mentioned, since the .flv, like the mp3 is progressively downloaded, you wouldn't be able to "seek" to any point in the file that has not yet been downloaded.

                          an example of a AS2 "event"  cue point used to load a second .swf at a particular time during the .flv playback.

                           

                          // This code controls the cue points //
                          ns.onCuePoint = function(evt:Object){
                              trace(evt.name);
                              trace(evt.time);
                              if(evt.name == "play_vid1") {
                                  trace("YO!Loading wide_holder!");
                                  wide_holder.loadMovie("rm/images/black_bear.swf");
                              }

                              if(evt.name == "play_vid2") {
                            trace("YO!Loading standard_holder!");
                                  standard_holder.loadMovie("rm/images/sqis.swf");
                              }
                          };

                           

                          Good luck on your project!

                          Adninjastrator

                          • 10. Re: newbie: flash audio not playing
                            nobood09 Level 1

                            You have all been so helpful. I am having a terrible time understanding ActionScript, and taking things from tutorials and putting them into practice.

                             

                            Before I move onto the cue points and highlighting, I need to get this to play on my server. I did a simple test file where the audio is embedded. That seems to work fine when uploaded. What I'm struggling with now is combining the code for the click to play stop, and the embedded audio.

                             

                            Can you tell me how to change the code that I have so that the audio file is embedded from the library, and plays/stops when clicked? I've basically used what I had above and changed the URL lines to indicate the audio fromt he library but it's not working. Here's what it lookes like:

                             

                            stage.addEventListener(MouseEvent.CLICK, fl_ClickToPlayStopSound);

                             

                            var fl_SC:SoundChannel;

                             

                            //This variable keeps track of whether you want to play or stop the sound

                            var fl_ToPlay:Boolean = true;

                             

                            function fl_ClickToPlayStopSound(evt:MouseEvent):void

                            {

                            if(fl_ToPlay)

                            {

                            var sound:L57_passage_p1_1 = new L57_passage_1_1;

                            fl_SC = sound.play();

                            }

                            else

                            {

                            fl_SC.stop();

                            }

                            fl_ToPlay = !fl_ToPlay;

                            }

                             

                            thanks again.

                            • 11. Re: newbie: flash audio not playing
                              markerline Level 4

                              have you tried to change this line:

                               

                              var fl_SC:SoundChannel;

                               

                              to

                               

                              var fl_SC:SoundChannel = new SoundChannel();

                               

                              ?