Is there a problem with my emulator sound?

All your problems with Audio, Video and Images.

Is there a problem with my emulator sound?

Postby who1 » Sat Jul 24, 2010 6:54 pm

I have this code to play my sound
Code: Select all
public class W extends Activity {
   private MediaPlayer mMediaPlayer;

   public void onCreate(Bundle icicle) {
           super.onCreate(icicle);
           MediaPlayer mp = MediaPlayer.create(getBaseContext(), R.raw.bt);    mp.start();
           try {
            mMediaPlayer.prepare();
         } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
      mMediaPlayer.seekTo(0);
         }
           mMediaPlayer.start();
       }

              {}

       }

There are no errors, but there is no sound on the emulator. Could anyone tell me what to add to this code? Thanks.
who1
Freshman
Freshman
 
Posts: 5
Joined: Tue Jul 20, 2010 4:27 am

Top

Re: Is there a problem with my emulator sound?

Postby blundell » Tue Jul 27, 2010 8:17 am

You call .start() twice, and you call seekTo() for no reason

Have a look at:
ANDDEV Audio Sample
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Re: Is there a problem with my emulator sound?

Postby who1 » Wed Jul 28, 2010 8:22 pm

I changed the code
Code: Select all
package d.h;
import java.io.IOException;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;

public class W extends Activity {
   private MediaPlayer mMediaPlayer;

   public void onCreate(Bundle icicle) {
           super.onCreate(icicle);
           MediaPlayer mp = MediaPlayer.create(getBaseContext(), R.raw.bt);   
           try {
            mMediaPlayer.prepare();
         } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
     
         }
           mMediaPlayer.start();
       }

              {}

       }

But it still doesnt play on the emulator
who1
Freshman
Freshman
 
Posts: 5
Joined: Tue Jul 20, 2010 4:27 am

Re: Is there a problem with my emulator sound?

Postby blundell » Wed Jul 28, 2010 10:07 pm

See my last post
User avatar
blundell
Master Developer
Master Developer
 
Posts: 1610
Joined: Tue Nov 18, 2008 12:58 pm
Location: UK

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 23 guests