Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6561913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:38:47+00:00 2026-05-25T13:38:47+00:00

I managed to create an application in Blackberry that plays audio file, but it

  • 0

I managed to create an application in Blackberry that plays audio file, but it will only plays one file. I try to use a for loop to play a few audio files.

I managed to play it, but it did not play the whole sound of the audio files, it just play the first audio files and second for a few seconds, and stop playing after that. The files that played also play the sound overlap each other which should not be happening.

How to play the full sound of the audio files one after another in Blackberry without stopping?

Here is my code for the application that I created with the for loop:

    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
         */
        PlayMediaScreen()
        {
            String test1 = "Test(2seconds).mp3";
            String test2 = "Test(2seconds)2.mp3";
            String test3 = "Test(2seconds)3.mp3";
            String test4 = "Test(2seconds)4.mp3";
            String test5 = "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;
                }
                play(mp3);
            }
        }

        private void play(String mp3){

        Player p = null;

        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();



        }
    }
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:38:47+00:00Added an answer on May 25, 2026 at 1:38 pm

    Finally I get it, this is my code. 😀

    package mypackage;
    
    import javax.microedition.media.Manager;
    import javax.microedition.media.MediaException;
    import javax.microedition.media.Player;
    import javax.microedition.media.PlayerListener;
    
    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 implements PlayerListener
        {
            /**
             * Creates a new PlayMediaScreen object
             */
            Player p = null;
            String mp3 = ""; 
            String test1 = "Test2seconds.mp3";
            String test5 = "Test2seconds2.mp3";
            //String test6 = "Test2seconds3.mp3";
            String test4 = "Test2seconds4.mp3";
            String test2 = "blind_willie.mp3";
            String test3 = "blind_willie2.mp3";
    
    
            PlayMediaScreen()
            {
                mp3 = test1;
                play(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.addPlayerListener(this);
                    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();
                */
    
    
            }
    
            public void playerUpdate(Player player, String event, Object eventData) {
                // TODO Auto-generated method stub
                if (event.equals(PlayerListener.END_OF_MEDIA)) {
    
                    //String mp3 = ""; 
    
                    if( mp3.equals(test1) ) {
                        mp3 = test2;
                        //testing
                        System.out.println("The MP3 is " + mp3 + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    
                        play(mp3);
    
                        //testing
                        System.out.println("The MP3 FINISH PLAYING is " + mp3 + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    
                    }
                     else if( mp3.equals(test2) ){ 
                         mp3 = test3;
                        //testing
                        System.out.println("The MP3 is " + mp3 + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    
                        play(mp3);
    
                        //testing
                        System.out.println("The MP3 FINISH PLAYING is " + mp3 + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    
                     }
                     else if( mp3.equals(test3) ) {
                         mp3 = test4;
                         //testing
                        System.out.println("The MP3 is " + mp3 + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    
                        play(mp3);
    
                        //testing
                        System.out.println("The MP3 FINISH PLAYING is " + mp3 + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    
                     }                   
                     else if( mp3.equals(test4) ) {
                         mp3 = test5;
                        //testing
                        System.out.println("The MP3 is " + mp3 + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    
                        play(mp3);
    
                        //testing
                        System.out.println("The MP3 FINISH PLAYING is " + mp3 + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    
                     }
                     else if( mp3.equals(test5) ){
                         mp3 = null;
                         try {
                            player.stop();
                        } catch (MediaException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                         player.deallocate();
                         player.close();
                     }
    
                  }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ive managed to create an RMI application that does what i need it to
I've come across an issue where a web application has managed to create a
How should I create application wide utility/manager classes that read settings from the database?
I am still very new to the MVC framework, but I managed to create
I need to create a photo gallery service that is managed by users. I've
Let's create WinForms Application (I have Visual Studio 2008 running on Windows Vista, but
A web application has no make file unlike C++ or anything like that. However,
I create an Enterprise Application CustomerApp that also generated two projects CustomerApp-ejb and CustomerApp-war
Problem I'm trying to create an CUDA application that is well integrated with .net.
OK, I am creating a questionnaire application that is managed by a single user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.