Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 17
Registered: ‎02-06-2009
My Device: Not Specified

Problem to run mp3 audio file using media player in JDE 4.7 application.

[ Edited ]

Dear Friends,

 

I have found a problem to run a mp3 audio file in media player. When I run this code it gives me error like IllegalArgumentException. The code is as below.

 

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

 

 

 

import java.io.IOException;

import java.io.InputStream;

import javax.microedition.media.MediaException;

import javax.microedition.media.Player;

 

import net.rim.device.api.system.Application;

 

 

public class mediaplayertest extends Application 

{

 

public static void main(String []args)

{

BackgroundClass bc = new BackgroundClass();

bc.enterEventDispatcher();

}

 

}

 

 

class BackgroundClass extends Application

{

public BackgroundClass()

{

BackgroundThread bt = new BackgroundThread();

bt.start();

}

public class BackgroundThread extends Thread

{

 

public void run(){

 

try {

 

InputStream str = getClass().getResourceAsStream("/Dc14.mp3");

    Player player; 

player = javax.microedition.media.Manager.createPlayer(str, "audio/mpeg");

player.realize();

player.prefetch();

player.start();

 

 

} catch (IOException e) {

e.printStackTrace();

} catch (MediaException e) {

e.printStackTrace();

}

 

}

}

 

}

 

 

 

 

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

 

Please let me know where I am wrong.

 

Folder structure is as shown below image.

Folder Structure 

 

  I have use JDE 4.7 with testing in BlackBerry simulator 9530. Is it due to media file size ?? Size of my this file is 14 MB.


Message Edited by only_vimal on 02-20-2009 05:54 PM
Developer
Posts: 40
Registered: ‎08-21-2008
My Device: Not Specified

Re: Problem to run mp3 audio file using media player in JDE 4.7 application.

[ Edited ]

I have tested your code with JDE 4.7 simulator-9500 and its works fine without any exceptions.

I suspect that you have not inserted the media file(in your case Dc14.mp3) to JDE. Check it out!.

Message Edited by raksat on 02-20-2009 05:36 PM
Raks
New Developer
Posts: 17
Registered: ‎02-06-2009
My Device: Not Specified

Re: Problem to run mp3 audio file using media player in JDE 4.7 application.

Thanks Raks for making hope alive,

 

I have already stored media file Dc14.mp3 in src/Audio folder. And my java file is in src folder of project. I confused more now because this code running fine in your system but not in mine.

 

Please help me defferent way. 

 

With Regards,

Vimal 

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Problem to run mp3 audio file using media player in JDE 4.7 application.

Vimal, In your code you have extended Application class twice. What are you trying to do, other than playing the audio.

Use Search. "Accept Solution" If the problem is resolved.
New Developer
Posts: 17
Registered: ‎02-06-2009
My Device: Not Specified

Re: Problem to run mp3 audio file using media player in JDE 4.7 application.

[ Edited ]

Thanks for point out this,  please let me know that how can i simply play media file successfully in this application. Where I miss key code ?

 

With Regards,

Vimal 

 

 

Message Edited by only_vimal on 02-20-2009 06:44 PM
Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Problem to run mp3 audio file using media player in JDE 4.7 application.

Hi Vimal, I would like to suggest you to go thru the below thread. It has a a very good collections of developers guide, which will help you to get started with Blackberry application development.

 

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&thread.id=13264

 

 


Use Search. "Accept Solution" If the problem is resolved.
New Developer
Posts: 17
Registered: ‎02-06-2009
My Device: Not Specified

Re: Problem to run mp3 audio file using media player in JDE 4.7 application.

Thanks BBDeveloper,

 

Please tell me that is there any maximum media file size limit to play it. Because I have tried your given following code. And it works for small mp3 file. I have tried it with 12 MB mp3 file which is stored in my application not in SD card. So I have first try with Dc12.mp3 (size 4 mb) and it play nicely.

 

Then I had tried with Dc13.mp3 (size 4.5 mb) and it also play nicely. After this I had tried with Dc14.mp3 (size 12.5 mb) and application didn't play this file and application has automatically played previous file Dc13.mp3.

 

I tried to change file name again to play media file Dc12.mp3 again but unfortunately my application plays media file Dc13.mp3 even I had deleted this file from my application and buit project twice.

 

 

Here is your given code. 

 

 AudioTest.java

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

import java.io.IOException;
import java.io.InputStream;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import net.rim.device.api.ui.*;


public class AudioTest extends UiApplication
{
    public static void main(String []args)
    {
        AudioTest at = new AudioTest();
        at.enterEventDispatcher();
    }
    
    public AudioTest()
    {
        pushScreen(new BackgroundClass());
    }
}

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

BackgroundClass .java

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

import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.*;

class BackgroundClass extends MainScreen
{
    public BackgroundClass()
    {
        BackgroundThread bt = new BackgroundThread();
        bt.start();
    }

    public class BackgroundThread extends Thread
    {
        public void run()
        {
            try
            {
                InputStream str = getClass().getResourceAsStream("/Dc14.mp3");
                Player player;
                player = javax.microedition.media.Manager.createPlayer(str, "audio/mpeg");
                player.realize();
                player.prefetch();
                player.start();
            }
            catch (IOException e)
            {
                System.out.println("Coming here "+e.toString());
            }
            catch (MediaException e)
            {
                System.out.println("MediaException "+e.toString());
            }
        }
    }
}

 

 

With Regards,

Vimal 

Highlighted
Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Problem to run mp3 audio file using media player in JDE 4.7 application.

Your Dc12.mp3 and Dc12.mp3, as you claiming after delete also it is playing the same file. If this is the case please check the Contnet of your Dc12.mp3. I feel the Dc12.mp3 and Dc13.mp3 are having same content, Or check you deleted the file in appropriate project and you running the correct project.

 

For not playing 12MB file, IT may be because of the memory issue. To tell you more specifically, tell us what kind of exception you getting.

 

I suggest you to go thru the PlayerListener interface and check what all the events it is generating.

 

Are you testing on simulator or the Device. Post more details about this too.


Use Search. "Accept Solution" If the problem is resolved.
New Developer
Posts: 17
Registered: ‎02-06-2009
My Device: Not Specified

Re: Problem to run mp3 audio file using media player in JDE 4.7 application.

Hi BBDeveloper,

 

1. Each file Dc12.mp3, Dc13.mp3 and Dc14.mp3 has different content to play.

2. I have also checked that files deleted properly and runnig appropriate project. 

3. I have developed this application in JDE 4.7.

4. I am testing this application in Simulator 9530 Verizon.

 

With Regards,

Vimal 

 

 

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Problem to run mp3 audio file using media player in JDE 4.7 application.

If this is the case, the result should also be same.

Have you tried playing the Audio on Realtime device?

I suggest you to split the files and use it in your application.


Use Search. "Accept Solution" If the problem is resolved.