Find Your Forum
  
Welcome, Guest. Please login or register.
Did you miss your activation email?

News: HTC Evo 4G by Sprint
Instinct Forum, Samsung Instinct message board, Samsung Instinct By Sprint, Samsung Instinct phone, new Samsung Instinct, Samsung Instinct phone, Sprint Instinct, Samsung Instinct phone
Best Screen Protector for Samsung Instinct                 Free Sprint Phones and Cheap Plans
                Samsung Instinct Scratch Protection
Pages: [1]
Reply Print
Author Topic: [J2ME] Problem playing multiple sounds in application  (Read 1659 times)
joseamirandavelez
[I][N][S][T][I][N][C][T]
********

Cookies: 4
Phone Before Samsung Instinct: SPH-A640
Hometown: Corozal, PR
Posts: 427


That's not a bug - Its a feature request!

joseamirandavelez
WWW
« on: May 28, 2009, 10:40:52 PM »

Hi guys,

I'm trying to learn how to play sounds (MP3's) on an app. I have it working but I can only play one file and then it does not play anything else.

I created a class that does everything:

Code:
package SoundMaker;

import javax.microedition.media.*;
import java.io.*;

public class PlayXYZ implements Runnable{
    public void run()
    {
        try
        {
            InputStream in = getClass().getResourceAsStream("/XYZ.mp3");
            Player player = Manager.createPlayer(in, "audio/mpeg");
            player.start();
        }
        catch (Exception e) {
            //showException(e);
            return;
        }
    }
}

I am using the following code to initialize an instance of the class, a new thread and start it:

Code:
PlayXYZ p = new PlayXYZ();
Thread myThread = new Thread( p );
myThread.start();

I'm using a new thread because I though it may be possible to play multiple sounds with them, but it may not be possible...

Alright. The problem is when I create another instance of my class and a new thread. It does not play anything. Only the first sound plays...

For now, I dont care if it does not play multiple sounds, but I would like to be able to play a sound after the other. Or stop a sound when another sound starts, just like KBPiano.

Any help would be greatly appreciated.
Logged

-Jose

"A bug is a feature that didnt make it to the manual."
KillerBeagle
Instinct Fanatic
******

Cookies: 234
Hometown: Wilmington
Posts: 1282



« Reply #1 on: May 29, 2009, 04:05:32 PM »

I don't know what will happen to the Player in this case.  You created it inside the thread, and Player.play is non-blocking, so the Player is still running while the thread is already terminated.  At that point I don't see how you could stop it to start another sound, because the context in which it was created is now gone.

KBpiano just uses a single Player that gets started and stopped as needed.  I'm not sure of the hardware/OS capabilities for playing multiple sounds simultaneously; I've never tried it.
Logged
joseamirandavelez
[I][N][S][T][I][N][C][T]
********

Cookies: 4
Phone Before Samsung Instinct: SPH-A640
Hometown: Corozal, PR
Posts: 427


That's not a bug - Its a feature request!

joseamirandavelez
WWW
« Reply #2 on: May 29, 2009, 05:07:18 PM »

Thats a good point. I think Im going to take the thread code out and try stopping the player. Now, I though the player was supposed to stop itself after the sound finished...
Logged
joseamirandavelez
[I][N][S][T][I][N][C][T]
********

Cookies: 4
Phone Before Samsung Instinct: SPH-A640
Hometown: Corozal, PR
Posts: 427


That's not a bug - Its a feature request!

joseamirandavelez
WWW
« Reply #3 on: May 29, 2009, 05:08:38 PM »

i guess i'm gonna have to stop it when i wanna play a new sound.

Thanks for the help!
Logged
KillerBeagle
Instinct Fanatic
******

Cookies: 234
Hometown: Wilmington
Posts: 1282



« Reply #4 on: May 29, 2009, 05:18:26 PM »

It should stop when the sound is finished, but if you want to stop it early and start a new sound, you definitely need to keep that Player around.  I usually do a stop before starting "just in case" except where I'm just creating the instance for the first time.

I'd still like to know if multiple simultaneous sounds are possible from an app - maybe I'll do some experiments too.  If I recall, Player allowed a choice of playing in the background or not, but I couldn't get two playing just by using one in the background and one not.  It seems like multiple Players should work, but who knows what the phone allows...
Logged
joseamirandavelez
[I][N][S][T][I][N][C][T]
********

Cookies: 4
Phone Before Samsung Instinct: SPH-A640
Hometown: Corozal, PR
Posts: 427


That's not a bug - Its a feature request!

joseamirandavelez
WWW
« Reply #5 on: May 29, 2009, 07:51:08 PM »

Well, I have not seen any app that can play more than one sound at the same time. I'll post anything I find...
Logged
joseamirandavelez
[I][N][S][T][I][N][C][T]
********

Cookies: 4
Phone Before Samsung Instinct: SPH-A640
Hometown: Corozal, PR
Posts: 427


That's not a bug - Its a feature request!

joseamirandavelez
WWW
« Reply #6 on: May 29, 2009, 08:01:35 PM »

What sound format do you use? I'm using MP3's but they dont play on the emulator...
Logged
joseamirandavelez
[I][N][S][T][I][N][C][T]
********

Cookies: 4
Phone Before Samsung Instinct: SPH-A640
Hometown: Corozal, PR
Posts: 427


That's not a bug - Its a feature request!

joseamirandavelez
WWW
« Reply #7 on: May 29, 2009, 09:31:43 PM »

OK. Now I'm lost. I got rid of the classes and threads stuff and created a function to handle the sound playing.

Code:
protected boolean playSound(String snd, String type){
            try
                {
                if(player!=null){
                    player.stop();
                }
                is = getClass().getResourceAsStream(snd);
                    player = Manager.createPlayer(is,type);
                    //player.realize();
                    player.prefetch();
                    player.setLoopCount(1);
                    player.start();
                }
                catch(Exception e)
                {}
            return true;
        }

And now the sound would not stop looping. I am calling this function from:

Code:
protected void pointerPressed(int x, int y)
        {
            m_y = y;
            m_x = x;
            repaint();
            if(x>0 && x<75 && y>18 && y<142){
                playSound("/ring.mp3","audio/mpeg");
                //playSound("/ring.wav","audio/x-wav");    // this is for debugging with the emulator
                sound="Ring";   /This is for displaying what sound is playing
            }
...

On the emulator, the thing keeps looping and when I press on the same sound it stops the player and start again as it is supposed to do. But if I play on another sound it does not stop.

On the phone, it keeps looping but as soon as I press any sound it stops and then does not wanna play anything else.

I tried closing the player and the input stream but nothing works...

This is really confusing...
Logged
Pages: [1]
Reply Print
Jump to:  

Got a new phone? Find the forum here


Subject Started by Replies Views Last post
Handmark application problem
General Instinct Discussions
rjh1968 5 792 Last post October 01, 2008, 08:36:12 AM
by - Z -
Gmail Releases 2.0 Client for J2ME Phones - Doesn't Run on Instinct « 1 2 »
Third-Party Instinct Software
criley98 28 6012 Last post December 15, 2008, 12:42:47 PM
by mbrulla
Blender 3d to J2me
Instinct Application Developer
napsterking 8 1753 Last post December 24, 2008, 12:44:59 AM
by napsterking
Email Application Auto-Receive Problem
General Instinct Discussions
Jonsey5484 3 906 Last post March 06, 2009, 01:05:26 PM
by Jonsey5484
Instinct sounds
General Instinct Discussions
derrrface 0 322 Last post September 12, 2009, 12:25:00 AM
by derrrface




Galaxy S3 | Galaxy Note | Galaxy Nexus | Kindle Fire | Atrix 4G | Motorola Xoom | Windows Phone 7
Nokia Lumia | Top Hosts | Samsung Galaxy Tab | Samsung Galaxy S2 | Samsung Galaxy S | Samsung Wave
HTC Evo 3D | HTC Evo 4G | HTC Incredible | HTC Incredible 2 | HTC Incredible S | HTC Thunderbolt
Motorola Droid Razr
| HTC Desire | HTC Desire HD | HTC Desire Z | HTC Desire S | HTC Wildfire
Motorola Droid | Galaxy Indulge | Nokia N8 | Droid Charge | Droid X | Droid X2 | Droid 2| Droid 3 | Fascinate
HTC Sensation | HTC Flyer | LG Revolution | Asus Transformer | Xperia Play | iPhone 4 | Nexus S | Droid Bionic
HTC One | HTC Wildfire S | HTC Droid Eris


This is an Un-Official fan based Website. The views expressed on this website are solely those of the proprietor, or contributors to the site, and do not necessarily reflect the views or opinions of the parties it covers, and is not affiliated with, endorsed or sponsored by parties involved.
If you have a problem with any of the content posted on this website, please contact "sales@verticalscope.com"
Term of Use | Privacy Policy | BlackRain 2006 by, Crip





















CopyRight 2008 www.instinct-samsung.com
Powered by SMF 1.1.11 | SMF © 2006-2007, Simple Machines LLC