Auto-play audio file

Hello everyone!

I have a sound setup file that works very well, however, I can't get the audio to start playing as soon as the entrance. I tried the using the code: samplesound.play ();  and he plays but when you click on the play button, the audio repeats and the audio file that began as soon as the entry do not respond to commands.

You can download the actual files to:

http://artisture.com/Digital/posted_sound_files.zip

Please help and thanks in advance!

edlearner

Here's a simple way:

----------------------

var mySound:Sound;

var myChannel:SoundChannel;

var isPlaying:Boolean = false;

var p:uint = 0;

mySound = new sound;

mySound.load (new URLRequest ("samplesound.mp3"));

play_btn.addEventListener (MouseEvent.CLICK, playSound);

stop_btn.addEventListener (MouseEvent.CLICK, stopSound);

pause_btn.addEventListener (MouseEvent.CLICK, pauseSound);

function stopSound(myEvent:MouseEvent):void

{

myChannel.stop ();

p = 0;

isPlaying = false;

}

function playSound(myEvent:MouseEvent):void

{

playTheSound();

}

function pauseSound(myEvent:MouseEvent):void

{

If (isPlaying)

{

p = Math.floor (myChannel.position);

myChannel.stop ();

isPlaying = false;

}

}

function playTheSound (): void

{

If (! isPlaying)

{

myChannel = mySound.play (p);

isPlaying = true;

}

}

playTheSound();

---------------------

Tags: Adobe Animate

Similar Questions

  • How to play audio files, one after the other?

    Hi, I try to create an application that tries to read audio files a few one after the other. I've created a loop for playing audio files. But only the first track is played and the second song is playing only about 5 seconds while the rest do not get played at all and the two files that have played, pieces overlap, which is not supposed to be. Can you guys help me? I need urgent assistance that I need to finish it tonight.

    Here are my codes I created for the application:

    package mypackage;
    
    import javax.microedition.media.Manager;
    import javax.microedition.media.MediaException;
    import javax.microedition.media.Player;
    import java.lang.Class;
    import javax.microedition.rms.RecordStore;
    import java.io.InputStream;
    import java.io.ByteArrayInputStream;
    import net.rim.device.api.media.protocol.ByteArrayInputStreamDataSource;
    import net.rim.device.api.system.*;
    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.component.*;
    import net.rim.device.api.ui.container.MainScreen;
    import net.rim.device.api.ui.extension.container.*;
    import net.rim.device.api.ui.UiApplication;
    import java.io.IOException;
    
    public class PlayMedia extends UiApplication{
        /**
         * Entry point for application
         * @param args Command line arguments (not used)
         */
        public static void main(String[] args){
    
            PlayMedia theApp = new PlayMedia();
            theApp.enterEventDispatcher();
        }
    
        public PlayMedia()
        {
    
            pushScreen(new PlayMediaScreen());
    
        }
        /**
         * A class extending the MainScreen class, which provides default standard
         * behavior for BlackBerry GUI applications.
         */
        final class PlayMediaScreen extends MainScreen
        {
            /**
             * Creates a new PlayMediaScreen object
             */
            public Player p = null;
            PlayMediaScreen()
            {
                String test3 = "Test(2seconds).mp3";
                String test5 = "Test(2seconds)2.mp3";
                //String test6 = "Test(2seconds)3.mp3";
                String test4 = "Test(2seconds)4.mp3";
                String test1 = "blind_willie.mp3";
                String test2 = "blind_willie.mp3";
                String mp3 = null;
    
                for(int i=0;i<5;i++){
                    if(i == 0){
                        mp3 = test1;
                    }
                    else if(i == 1){
                        mp3 = test2;
                    }
                    else if(i == 2){
                        mp3 = test3;
                    }
                    else if(i == 3){
                        mp3 = test4;
                    }
                    else if(i == 4){
                        mp3 = test5;
                    }
                    //testing
                    System.out.println("Song is "+ mp3 + "???????????????????????????????????????");
    
                    play(mp3);
    
                    System.out.println("Song is "+ mp3 + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                }
            }
    
            private void play(String mp3){
    
            InputStream stream = (InputStream)this.getClass().getResourceAsStream("/" + mp3);
    
                try {
                    //p = Manager.createPlayer(source);
                    p = Manager.createPlayer(stream, "audio/mpeg");
                    p.realize();
                    p.prefetch();
    
                    //testing
                    System.out.println("Creating Players!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                    System.out.println("The mp3 is " + mp3 + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
    
                    //testing
                    System.out.println("IO Exeception!!!!!!!!!!!!!!!!1 " + e);
    
                    //testing
                    System.out.println(p);
    
                } catch (MediaException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
    
                //testing
                System.out.println("Media Exeception!!!!!!!!!!!!!!!!1" + e);
    
                //testing
                System.out.println(p);
                }
                /*
                 * Best practice is to invoke realize(), then prefetch(), then start().
                 * Following this sequence reduces delays in starting media playback.
                 *
                 * Invoking start() as shown below will cause start() to invoke  prefetch(0),
                 * which invokes realize() before media playback is started.
                 */
                try {
                    p.start();
                } catch (MediaException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
    
                    //testing
                    System.out.println("Media Exeception for starting!!!!!!!!!!!!!!!!1" + e);
    
                    //testing
                    System.out.println(p);
                }
                /*
                try {
                    p.stop();
                } catch (MediaException e) {
                // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                p.deallocate();
                p.close();
                */
    
            }
        }
    }
    

    Please help me! Thanks in advance!

    What you will do, is add the PlayerListener and / if you have in your loop code would go in the treatment of the END_OF_MEDIA event. Once that noise has stopped you will start the next sound and add the listener of player.

    //Declarations
    PlayerListener pListen;
    String mp3 = "";
    
    ..........
    ..........
    
    pListen = new PlayerListener(){
       public void playerUpdate(Player player, String event, Object eventData) {
          if (event.equals(PlayerListener.END_OF_MEDIA)) {
             if( mp3.equals(test1) ) mp3 = test;
             else if( mp3.equals(test2) ) mp3 = test3;
             else if( mp3.equals(test3) ) mp3 = test4;
             .........
    
             InputStream stream = (InputStream)this.getClass().getResourceAsStream("/" + mp3);
             p = Manager.createPlayer(stream, "audio/mpeg");
             p.realize();
             p.prefetch();
             p.addPlayerListener(pListen);
             p.start();
          }
       }
    }
    
    InputStream stream = (InputStream)this.getClass().getResourceAsStream("/" + mp3);
    p = Manager.createPlayer(stream, "audio/mpeg");
    p.realize();
    p.prefetch();
    p.addPlayerListener(pListen);
    p.start();
    

    So, add the try-catch blocks.

  • Windows Media Player cannot play audio files

    Hi, I have Toshiba laptop, this is my baby, and all of a sudden I can't play sounds! When I click to play a song in windows media player, it says:

    Windows Media Player cannot play the file because there is a problem with the audio device. It might not be a sound device installed on your computer, it can be used by another program, or it may not work properly.

    I tried everything and I'm on my last nerve! Basically, I'm rubbish with computers, I do not understand this at all, I followed all the ways suggested by the section 'aid' in my computer and I can't always listen to 'The Feeling!' Please help, I'm going crazy here!

    Yes my friend. The computer world is really not easy to understand, and sometimes I wish that I could no longer live the island of computer.
    but you know, the development never stop.

    OK, now your problem; have you checked the Device Manager?
    You don't see any yellow exclamation next to the sound card?

    I think that you should first try reinstalling the audio driver. Of course, it s a very tips but especially it works essentially ;)

  • Use WMP to play audio files of older games triggers the Crash game

    I have a game more Microsoft called Age of Empires. The game has some cool sound effects, I went into the game directory and played some of the sounds with Windows Media Player. Now when I try to play the game, it crashes when these sounds are triggered.

    I learned that WMP adds a kind of coding for audio files when he plays, and that older games such as Age of Empires do not include this extra info so when the game tries to play the sounds, it crashes.

    I tried to uninstall the game completely and put it back and even delete audio files and their replacement, but he did not set. It is only the sounds that I played on WMP that cause the game to Crash, all the sounds I was not playing on WMP still work fine.

    Can you please tell me how to resolve this.

    Hi Halima,

    Thanks for your reply. I managed to solve the problem in a different way. I open each file with a program (I use Adobe Audition) for audio editing, you click Save under and saved all of the audio files as new mp3 files, crushing & replace the original files. I did it in bulk by opening all the audio files at the same time and choosing "save all".

    This seems to have removed the additional coding added to audio files in Windows Media Player and the game can play these audio files when triggered.

    That said, I do not understand why crushing & replacing the mp3 files fixed the issue so that the uninstall & reinstall the game does not - this method of relocation removed all files of game (including all audio files) and replace them with the original from disk files, but still they cannot be triggered by the game. Maybe the computer recognized them somehow as the same files that WMP had altered and automatically change them again. Very strange.

    Thank you

    David

  • Cannot play audio files on the Internet

    Original title: I don't hawe musick and sound on the internet

    When I want to lisen musick on internet, I can't. Why?

    I've been trying this drug, but I've been gething nothing so please help

    Hello

    1. are you able to listen to audio files stored on your computer?

    2. do you get an error message when you try to listen to music on the internet?

    3. What is the format of the files you are trying to play?

    4. which browser is installed on the computer?

    Proceed as if you have Internet Explorer installed on the computer.

    a: open Internet Explorer.

    b: click on Tools > Internet Options.

    c: now click on the Advanced tab.

    d: now navigate in the multimedia section.

    e: place a check mark the option " play sounds in Web pages.

    f: Click apply , then ok.

    Hope this information helps.

  • Why can't I play & audio file in windows Media Player

    I have audio files in my documents, as they will not play in Windows Media Player, which is my default player.

    You are welcome and thank you for the comments.

  • Windows Media Player will play audio files with the exception of midi files

    in my Windows 7 computer, Windows Media Player is called upon to play .mid and .midi files.  When I try to play the file, it says there is a problem with the audio device however, TI WMP plays videos, files mp3 with sound perfect.  Register for midioutID is set to the audio device by default with data 0xffffffff.  I've removed from the media database and allowed him to repopulate but still no sound.  All the settings to another computer running windows 7 that will play the midi files.  What's wrong?

    Hello

    I suggest you run the Fix - it from the link below and if it makes a difference. If the problem persists, turn off Windows Media Player, and then put it from the Windows features.

    Step 1:

    Solve the problems of Windows Media Player video and other media or library

    http://support.Microsoft.com/mats/windows_media_player_diagnostic

    Step 2:

    Disable Windows Media Player and then turn it on to Windows features and check if the problem persists.

    Disable and enable Windows Media Player and check if it opens.

    (a) click Start and select Control Panel.

    (b) click on programs and features.

    (c) click on or turn off Windows features turn on on the left side.

    (d) develop the features of media; clear the check box Windows Media Player.

    (e) click Yes and OK to continue.

    (f) restart the computer.

    Note: If Windows media player is already disabled, follow the steps mentioned below:

    After the restart, follow these steps:

    (a) click Start and select Control Panel.

    (b) click on programs and features.

    (c) click on or turn off Windows features turn on on the left side.

    (d) develop the features of media; Check the Windows Media Player.

    (e) click Yes and OK to continue.

    (f) restart the computer.

    For your reference:
    http://Windows.Microsoft.com/en-us/Windows7/turn-Windows-features-on-or-off

    It will be useful.

  • Windows media player does not play audio files downloaded from the Canon HF M41 HiDef camcorder

    I downloaded audio and video files from a Canon Vixia HF M41 camcorder to my computer.  When I try to read files with Windows Media Player, the video is fine but the audio is only a hum.  What codec must be installed to play audio, and where it is available for download?  My operating system is Windows 7, version 6.1 (Build 7601: SvcPack 1)

    Hello

    What type of file are you trying to play?

    Method 1:

    I suggest you follow the link and check.

    Play an audio or video file: frequently asked questions

    http://Windows.Microsoft.com/en-us/Windows7/play-an-audio-or-video-file-frequently-asked-questions

    Method 2:

    I suggest you follow the link and check.

    Codecs: Frequently asked questions

    http://Windows.Microsoft.com/en-us/Windows7/codecs-frequently-asked-questions

    See also:

    Tips for solving common audio problems

    http://Windows.Microsoft.com/en-us/Windows7/tips-for-fixing-common-sound-problems

  • Playing audio file recorded back - where is this feature in the sound recorder in Windows 7?

    Hello

    In past when I was with Windows Vista, I used sometimes to save my own speech and then read it, sometimes backward, with Windows 7, I noticed that 'play back' is an option in the recorder provided with Win 7, I was wondering if there is a way to play audio backward in Windows Media Player, or recorded another way to play audio backward with the tools provided with Windows 7 Home Premium.

    Hello

    The reverse-reading feature is more included. You will need investigate third-party products to take advantage of this feature.

    Note: Using third-party software, including hardware drivers can cause serious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the use of third-party software can be solved. Software using third party is at your own risk.

  • Windows Media Player-cannot play audio file

    recive, whenever I click for a song, a message saying:-"WMP encountered a problem when reading the file. - and that's all he says but I can burn and thin ripjust, ideas?

    Hello everyone thanks for any response,

    I have recive, whenever I click for a song (in WMP) a message saying: "WMP encountered a problem reading the file, for further assistance, click web help." - and that's all it says, so I followed the link, but there is no real doesn't answer him other then telling me to adjust my volume and that of a supposed "error number" that is not displayed in the message window that is 'real page window media player', but only in the description of the 'web help' page, as I had no problems with burning CD or rip in my mp3... can't seem to play music in my files. I hope you may be able to thwart this weird problem, I'll be waitting for any help thanks again

    Thank you all for your help I finished to restore the system to an earlu date, and all got better thanks.

  • Error when you try to play audio files in Windows Media Player C00D11B1

    I can't play 5% of the songs in my Media Player. the other 95%, I get an error C00D11B1.  What is going on?

    Mada

    Hi MadaJohnson,

    1. did you of recent changes on the computer?

    2 when was the last time it was working fine?

    You have a multiple bit rate (MBR) file or a live stream that contains more than 32 media streams. You try to read the MBR file or live stream in Windows Media Player on a computer that is running Windows XP or Windows Vista. However, Windows Media Player cannot read the MBR file or the live stream. Additionally, you receive an error C00D11B1 error code.

    See the link below and try them the steps mentioned, check if it helps.

    http://www.Microsoft.com/windows/windowsmedia/player/Webhelp/default.aspx?&mpver=11.0.5721.5230&ID=C00D11B1&ContextId=68&OriginalID=8007007E

    See also: http://support.microsoft.com/kb/974905

  • Error when you try to play audio files: Windows Media Player has encountered a problem reading the file. for further assistance, click web help

    8007007E tips

    There is also another number which is C00D11B1, but both have to do with the lock of the music in windows media player, the message said:-"Windows media player has encountered a problem reading the file; for help click web help. ""- and that of all, but when ' web help ' click on the show numbers that are 8007007E and C00D11B1 and average music, not Windows media player, y at - it someone with the same problem that has been able to solve? Thank you, let me know, if you don't mind, thank you again.

    I suggest re-download you WMP 11 from the following link and install it on top of the current installation:

    http://www.Microsoft.com/downloads/en/details.aspx?FamilyId=1d224714-e238-4E45-8668-5166114010ca

    Who help me?

    If this isn't the case, please report the file type (extension) of the file you are trying to play. For instructions on how to make Windows Explorer shows the file types, see this link:

    http://www.windowsreference.com/Windows-XP/how-to-view-all-file-extensions-in-Windows-XP

  • Error when you try to play audio files: Windows Media Player cannot access the file. The file may be in use, you won't have access to the computer where the file is stored

    Windows Media Player cannot access the file. The file may be in use, you won't have access to the computer on which the file is stored, or your proxy settings are may not be incorrect.

    I hope someone can help on Win 7 64 bit, music is taken on a disk usb2 external hard... I had no problem until today when the message in the title appeared next to each track, with a little red cross.

    I already deleted database library as suggested by some of the forums, also disabled the media as a feature of Win 7, rebooted and then re-enabled it.  I also disconnected externally and restarted that as well, I'm also the same mistake with a cd in the cd drive as well.

    Can anyone help?

    Hello

    This error may occur for one of the following reasons:
    The file is currently in use. Close the file and then try again.

    You are not allowed to access the location where the file is stored.

    Follow these steps to grant all permissions in the folder where the files are stored:
    1. right click on the folder on the external drive and click Properties.
    2. in the Properties window, click on Security tab.
    3. now, click Edit , and then click Add.
    4. now, type everyone in the box and click OK.
    5. check the full control box.
    6. click on apply and then click OK.

    You can also try the mentioned below as follows:

    1. click on start.
    2. go in Control Panel.
    3. Select "SOUND".
    4. double-click on speakers.
    5. click on the tab advanced and then uncheck the enable audio enhancements.

    Kind regards
    Amal-Microsoft Support.
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • No sound when using Firefox Hello despite Firefox playing audio files in Web sites correctly...

    I tried to use Firefox Hello to a conversation with my mother, who also uses Firefox. She could not get any sound, just the video image, despite the volume being defined properly controls. The microphone settings are correct, and in fact, I tried to call using two different computers but with the same result every time. I used successfully for a conversation with someone different. We all have two Windows 7 Professional v36.0 Firefox

    My mother is able to listen to the audio tracks in websites using Firefox but I don't hear a thing in Hello, what makes all this seems quite strange.

    Happy to say everything works now. Nothing has changed, so why it wasn't working the other day? One of life little mysteries but work he does, which is all that matters.

  • Error when you try to play audio files by using iTunes: the device doesn't seem to be connected.

    defective audio Setup Setup program

    Fast: The device doesn't seem to be connected. This continues with any audio in iTunes, so come on screen or through good headphones to work. I don't think it's the audio jack to the computer in the back. I've uninstalled and reinstalled Quicktime and iTunes, without change. I have s Dell Inspiron 530 with Vista Premium Home Edition

    Hello

    ·          Windows Media Player works fine?

    If the problem is with ITunes, then I would suggest that you contact the Apple support for more help with this.

    http://www.Apple.com/support/

Maybe you are looking for