Playing MP3 OGG or MID

All your problems with Audio, Video and Images.

Playing MP3 OGG or MID

Postby Afternundelite » Thu Nov 18, 2010 1:36 am

Hey!
I realize there are a lot of threads on this topic, but none of them really helped me solve my problem.

I'm trying to play a sound using MediaPlayer.

I thought I'd just try to make it work first, so I try to play the sound in onCreate().

I tried with .mp3, .ogg and .mid, but none of them seemed to work.

I have tried with some different variations of code.
Here is the different code I've tried to use. I usually get an IO-exception.
PS. Writing for 1.6+


Code: Select all
MediaPlayer mp = MediaPlayer.create(this, R.raw.intro1);
            mp.start();


Code: Select all
            MediaPlayer mMediaPlayer = new MediaPlayer();
         Uri musicfile = Uri.parse("android.resource://" +
                 getPackageName() + "/" + R.raw.intro1);
mMediaPlayer.reset();
try {
     mMediaPlayer.setDataSource(getApplicationContext(), musicfile);
     mMediaPlayer.prepare();
     mMediaPlayer.start();
} catch (IllegalArgumentException e) {
     e.printStackTrace();
     statsButton.setText("illegarg");
} catch (SecurityException e) {
     e.printStackTrace();
     statsButton.setText("securi");
} catch (IllegalStateException e) {
     e.printStackTrace();
     statsButton.setText("state");
} catch (IOException e) {
    statsButton.setText("io");
     e.printStackTrace();
}



The first piece of code just tells me the application has stopped unexpectedly because I'm not able to catch an IO-exception with it.

The other piece of code gives me the io-exception.

Anyone with a solution out there, or just a contribution would help!
Much appreciated!
Afternundelite
Freshman
Freshman
 
Posts: 5
Joined: Thu Nov 18, 2010 1:26 am

Top

Re: Playing MP3 OGG or MID

Postby Schermvlieger » Thu Nov 18, 2010 9:43 am

Hi Afternundelite,

I don't know what you are trying to achieve in the first two lines of code, but the second part should work.
Have a look at the logcat while you run it and see what kind of error occurs.
Schermvlieger
Senior Developer
Senior Developer
 
Posts: 159
Joined: Fri Feb 26, 2010 1:37 pm

Re: Playing MP3 OGG or MID

Postby Afternundelite » Thu Nov 18, 2010 11:59 am

This is the error messages i get when using the Dalvik debug monitor:
Seems to me that the mediaplayer cant find the file, but the file is in /raw. .ogg files should work, right?
Anyways, if anyone knows how to solve this it would be great!

11-18 11:56:32.392: DEBUG/MediaPlayer(354): Couldn't open file on client side, trying server side
11-18 11:56:32.652: ERROR/PlayerDriver(31): Command PLAYER_SET_DATA_SOURCE completed with an error or info PVMFErrNotSupported
11-18 11:56:32.662: ERROR/MediaPlayer(354): error (1, -4)
11-18 11:56:32.672: WARN/System.err(354): java.io.IOException: Prepare failed.: status=0x1
11-18 11:56:32.672: WARN/PlayerDriver(31): PVMFInfoErrorHandlingComplete
11-18 11:56:32.702: WARN/System.err(354): at android.media.MediaPlayer.prepare(Native Method)
11-18 11:56:32.702: WARN/System.err(354): at org.me.tamtestrevive.Cow$7.onClick(Cow.java:1034)
11-18 11:56:32.712: WARN/System.err(354): at android.view.View.performClick(View.java:2344)
11-18 11:56:32.712: WARN/System.err(354): at android.view.View.onTouchEvent(View.java:4133)
11-18 11:56:32.712: WARN/System.err(354): at android.widget.TextView.onTouchEvent(TextView.java:6510)
11-18 11:56:32.722: WARN/System.err(354): at android.view.View.dispatchTouchEvent(View.java:3672)
11-18 11:56:32.722: WARN/System.err(354): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
11-18 11:56:32.722: WARN/System.err(354): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
11-18 11:56:32.722: WARN/System.err(354): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
11-18 11:56:32.732: WARN/System.err(354): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1712)
11-18 11:56:32.732: WARN/System.err(354): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1202)
11-18 11:56:32.742: WARN/System.err(354): at android.app.Activity.dispatchTouchEvent(Activity.java:1987)
11-18 11:56:32.742: WARN/System.err(354): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1696)
11-18 11:56:32.742: WARN/System.err(354): at android.view.ViewRoot.handleMessage(ViewRoot.java:1658)
11-18 11:56:32.752: WARN/System.err(354): at android.os.Handler.dispatchMessage(Handler.java:99)
11-18 11:56:32.752: WARN/System.err(354): at android.os.Looper.loop(Looper.java:123)
11-18 11:56:32.762: WARN/System.err(354): at android.app.ActivityThread.main(ActivityThread.java:4203)
11-18 11:56:32.762: WARN/System.err(354): at java.lang.reflect.Method.invokeNative(Native Method)
11-18 11:56:32.772: WARN/System.err(354): at java.lang.reflect.Method.invoke(Method.java:521)
11-18 11:56:32.772: WARN/System.err(354): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
11-18 11:56:32.772: WARN/System.err(354): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
11-18 11:56:32.772: WARN/System.err(354): at dalvik.system.NativeStart.main(Native Method)
Afternundelite
Freshman
Freshman
 
Posts: 5
Joined: Thu Nov 18, 2010 1:26 am

Re: Playing MP3 OGG or MID

Postby Schermvlieger » Thu Nov 18, 2010 1:22 pm

A quick google search on the error in your logcat yielded:

http://www.remwebdevelopment.com/dev/a6 ... s0x1-.html
Schermvlieger
Senior Developer
Senior Developer
 
Posts: 159
Joined: Fri Feb 26, 2010 1:37 pm

Re: Playing MP3 OGG or MID

Postby Afternundelite » Thu Nov 18, 2010 5:02 pm

Thanks, that was great but when I try that I get the error:
11-18 16:33:14.903: ERROR/Cow(400): java.io.FileNotFoundException: /data/data/org.me.tamtestrevive/files/test.mp3

I tried putting the file in the root directory of the project, is that correct?
Afternundelite
Freshman
Freshman
 
Posts: 5
Joined: Thu Nov 18, 2010 1:26 am

Re: Playing MP3 OGG or MID

Postby Schermvlieger » Thu Nov 18, 2010 5:40 pm

No you should keep your music media files in your raw folder. It is not clear to me why you are having these problems, sorry. You are using the code I put in a different thread on this site earlier. I am using this code in a number of my applications to play midi files, and experience no problems. I recommend trying it with some different media files (also .mid and .mp3) to see if the problem lies there.
Schermvlieger
Senior Developer
Senior Developer
 
Posts: 159
Joined: Fri Feb 26, 2010 1:37 pm

Top

Re: Playing MP3 OGG or MID

Postby Afternundelite » Fri Nov 19, 2010 1:03 am

All right, thanks a lot for all the help man. I seem to be hitting my head against the wall on this one. There must be some small issue I'm not getting.

You wouldn't happen to have a small project you could share just so I could see some code actually working?
Would be great!
Afternundelite
Freshman
Freshman
 
Posts: 5
Joined: Thu Nov 18, 2010 1:26 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 29 guests