How to play a sound file before you exit an application?

Hey guys, I'm a newbie.

I need dev an app it will play a sound file(mp3 perhaps) before release the app that my code is as follows:

playAudio();       UiApplication.getUiApplication().invokeLater(new Runnable() {
                public void run() {
                    close();
                }
            }, 500, false);

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

    private void playAudio() {
        // first we need to find the supported content types
        String types[] = Manager.getSupportedContentTypes(null);
        for (int cnt = types.length - 1; cnt >= 0; --cnt) {
            if (types[cnt].equals("audio/mpeg")) {
                // this sample demonstrates playing an MP3 file that has been
                // added as a resource to the project
                try {
                    // retrieve the MP3 file
                    InputStream is = getClass().getResourceAsStream(
                            "/sound/sound.mp3");
                    // create an instance of the player from the InputStream
                    Player player = javax.microedition.media.Manager
                            .createPlayer(is, "audio/mpeg");
                    // player.addPlayerListener(this);
                    player.realize();
                    player.prefetch();

                    VolumeControl volumeControl = (VolumeControl) player
                            .getControl("VolumeControl");
                    volumeControl.setLevel(100);

                    // start the player
                    player.start();

                } catch (Exception ex) {
                }
            } else if (types[cnt].equals("audio/x-wav ")) {
                // this is where you would play wav files
            } else if (types[cnt].equals("audio/midi ")) {
                // this is where you would play midi files
            }

        }
    }

the above code works fine on the Simulator, but not bad in real device (bb 9550). It closed just the app without playing the audio file. does anyone have a better solution?

(Note: the mp3 file is very short, less than 0.5 s)

first of all, I suggest you not to use invokelater like that, it's mainly to put things in the event queue and a system.exit does not queue. You can use a thread or a timer.

Second, I guess that 500 ms is not enough time for your system to play audio properly. I also suggest to put the audio player in an own thread.

Tags: BlackBerry Developers

Similar Questions

  • How to play image sound and moving of AVI file

    Hello

    I'm using LabVIEW 2010 and making the program to play image sound and moving to AVI file at the same time.

    I could play animated image of AVI file using "AVI OPEN.vi".

    However I couldn't play the sound file to AVI.

    Please give me an opinion on this issue.

    Hi yosuke

    If am not wrong you can do with the Windows Media Player ActiveX control.

  • I received this e-mail supposedly from Itunes. Back up and protect your media and Apps.id files before you lose.  Is - is this legitimate?

    I received this e-mail supposedly from Itunes. "Save and protect your media and Apps.id files before you lose it."  Is - is this legitimate?

    No, it's a phishing attempt - you can transfer to Apple: [email protected] and then delete him.

    Phishing and similar e-mail: Phishing and other suspicious emails

    The phishing emails: identifying fraudulent "phishing" email - Apple Support

    ITunes real e-mails: identification of legitimate on the iTunes Store - Apple Support emails

    View the purchase history of your account: view the history of your purchases from the iTunes Store - Apple Support

  • How can I block my number before you make a call

    How can I block my number before you make a call? Thank you!

    Settings > phone > display my number: OFF

  • I'm going to erase my media Cache files before you start a new project, but when I go to/Library/Applications/Common/there is no media Cache folder. I have never had this problem before and am 10.9.5 OS and using clues CS6?

    I'm going to erase my media Cache files before you start a new project, but when I go to/Library/Applications/Common/there is no media Cache folder. I have never had this problem before and am 10.9.5 OS and using clues CS6?

    Hi Dave,.

    The location is ~/Library/Application Support/Adobe/Common to be exact.

    Make sure that you type the TILDE (~) key.

    When in the Finder, click the go > go to folder... > Type ~/Library and navigate to Application Support/Adobe/Common

    Thank you

    Regalo

  • How to export a .sql file, I created from Oracle Application Express of SQL Server Management 2012?

    Hello

    I was wondering if you could help me.

    I'm trying to find out how to export a .sql file, I created from Oracle Application Express of SQL Server Management 2012? I'm not very technical, but it seems that the Oracle code does not work with SQL Management Studio when I drag the file inside.

    I need the database Oracle express and its data to enter in SQL Management Studio, so any help would be much appreciated!

    Thank you.

    Hello

    Your question is beyond the scope of this community.

    Please repost your question in the SQL Server TechNet Forums.

    https://social.technet.Microsoft.com/forums/SQLServer/en-us/home?category=SQLServer

    See you soon.

  • After recording a song using sound recorder, he continues repeatedly and repeatedly in a loop during playback. How to play only once? Thank you!

    I'm recording guitar and vocals on tape - about 2 minutes. When I play it back, the song starts again whenever it ends. How to stop after a reading without locking system?

    Hello

    Please contact Microsoft Community Forum!

    From the description of your post I see you facing problems with the saved file.

    Quick questions:

    1. How are trying to play the saved file? Is it through of tape recorder or another program?
    2. What happens when you save the full song and reading?
    3. He played only once after the restart of the song or it keeps on game till stop you it manually?

    Please come back with more information on the issue so that we can help you better.

    Might be possible that the repeat mode is enabled; try to check the settings within the program and check:

    Using the windows-related issues feel free to post on the Microsoft Community Forum.

  • How to play a sound stored in myRIO

    Hello

    How could I call a file saved in the usr/local/sbin in myRIO and send it to play? Thank you...

    I made this way. I turned the sound sample in a table (sound sample) and in another VI, I read this sample (creator of the ring). It works very well.

  • How to play several audio files at the same time and mute toggle some voices?

    Hi all

    Forgive me if this is mentioned elsewhere and kindly point me in the right direction.  I'm a kid with flash and action script so if you are in doubt, error on the side of more specific in your response, there is a lot of vocabulary I still don't know.

    The goal:

    I have 4 audio files which are Soprano, Alto, tenor and low voice of a musical example.  The result should allow the user to play all 4 voices at once and dumb voice specific to hear all the possible combinations of voices playing together or solo.  I imagined a check box at the beginning of each rated musical line that puts that voice muted when checked.

    It would be ideal to have the game, interrupt and stop reproduction choices where 'Stop' resets playback at the start and 'Pause' maintains the current place in time and takes over from there, once playback is started again.

    I am able to get the simple audio files to play from a single button, but I am struggling to find how to link multiple audio files to start at the same time by a single button.  I found this link: https://forums.adobe.com/thread/1069107?start=0 & tstart = 0

    where the last message mentions the use of tables, but being a complete beginner, I don't completely understand what they are doing.

    I know it's a big piece of questions at once, but if you could meet any part of it, or direct me to a tutorial/instructions, I would really appreciate it.

    Thank you for taking the time to help others

    use:

    kglad wrote:

    use:

    import flash.events.MouseEvent;

    import flash.media.SoundTransform;

    var soprano: Sound = new Soprano();

    Var high: Sound = new Alto();

    var tenor: Sound = new Tenor();

    var bass: Sound = new Bass();

    Ash var: Array = [soprano, alto, tenor, low];

    var offsetA:Array =]

    var st: SoundTransform = new SoundTransform();

    play_btn.addEventListener (MouseEvent.CLICK, playF);

    pause_btn.addEventListener (MouseEvent.CLICK, pauseF);

    stop_btn.addEventListener (MouseEvent.CLICK, stopF);

    playF function (e: MouseEvent): void {}

    for (var i: int = 0; i)< sounda.length;="" i++)="">

    This ["sc_" + i] = [i] Sunda () .play;

    }

    }

    function pauseF (e: MouseEvent): void {}

    for (var i: int = 0; i)< sounda.length;="" i++)="">

    offsetA [i] = this ["sc_" + i] .position;

    This ["sc_" + i]. Stop();

    }

    }

    function stopF (e: MouseEvent): void {}

    for (var i: int = 0; i)< sounda.length;="" i++)="">

    offsetA [i] = 0;

    This ["sc_" + i]. Stop();

    }

    }

    function unpauseF(e:MouseEvent):void {}

    for (var i: int = 0; i)< sounda.length;="" i++)="">

    This ["sc_" + i] = Sunda [i] .play (offsetA [i]);

    }

    }

    function muteF(i:int):void {}

    St.volume = 0;

    This ["sc_" + i] .soundTransform = m;

    }

    function unmuteF(i:int):void {}

    St.volume = 1;

    This ["sc_" + i] .soundTransform = m;

    }

  • How to play the video file from Gigashot A40FE?

    I have 40 GB A40FE cam gigashot.

    I can't able to play the video file from this cam. no support for the folder.

    Please give me answer.
    How to play that format or I want to convert or download any player for whom?

    Hello

    Have you tried to read this file using the VLC Player?

    It is a small player and the best is that it is just for free! :)
    He plays most file types, and I think that you should test.

    See you soon

  • How to play a sound on a button to the bottom of the State?

    Hello

    That is my question. How to play sound on CLICK or down state of the button? I don't know how to slap a sound on the timeline, but not how to put specifically for the button and that's down from the State.

    Thanks for the help in advance.

    go to the scenario of the button and attach a sound to its low chassis.   You probably want the sync event property.

  • How can I open an attachment before you save it?

    I'm used to be able to open an attachment before you choose to save it. Now I can just save it. Then I have to locate where it is save and open. PDF is not always open in Adobe. I have the most recent Adobe. It is a new problem for me to use gmail and firefox.

    Hello

    Please open settings and applications (optionally) see if the types of files (format pdf, jpeg, png) have a correct action. If they always ask they will be asked where to save the file or you want to open with application. If they are save, then they will be saved without asking.

    For more information, you can read the following:
    http:// http://kb.mozillazine.org/File_types_and_download_actions

    also read the following:

    More info

    It will be useful.

    You can return to your problem and we will try to help you.

  • How can I easily save files before wipe me and reload Windows XP costs?

    I am currently running Windows XP SP3, but the last windows disc I have is Windows XP SP2. I was infected with a virus and spin a pretty old computer so a wipe and reload would benefit performance considerably on my PC at home.

    Of course you will need an external hard drive to save your files.  You can copy the files yourself by dragging and dropping, but that sometimes limited races in the path of 256 bytes.  Another solution is to use the Microsoft NTBackup utility, and then restore the files selected after your re - install Windows.  Ensure that you do not restore infected files.

    "How to use the backup utility to back up files and folders in Windows XP Home Edition"
      < >http://support.Microsoft.com/kb/308422 >

    HTH,
    JW

  • EqualLogic - how to level a new table before you add to the Group

    I have a new table which is v7 and I try to add a group of v8.  It won't join the group due to version incompatibility.  How to pass it to v8 so I can join the Group?  Thank you.

    Hello

    Create a new group with one member.  I wouldn't use the Remote Setup Wizard to do this.  Who sets policy RAID that requires you to wait that ends before you can upgrade the firmware.

    I would rather the serial port.  Then, you need to only configure port network and the new IP group.

    Once you answer the basic questions are the GrpName > cli prompt you can then transfer the kit to upgrade and update the firmware.

    Once you run the "update" process and restarted the table, reconnect and make sure it is in the new revision.  GrpName > show Member which will show.

    The CLI run "reset" to return unit to factory reset, and you can now add in your other group.

    Kind regards

    Don

  • The highlight function copies the files before you move or delete action

    Windows 7

    Press Alt and control, then click on files with the mouse to highlight, the intention is to move to another location or delete them; but instead, the 'system' copies the files highlight! How do prevent us this from happening?

    Thank you

    To select or deselect files that you hold down the CTRL key, and then click each file.

Maybe you are looking for