| Author |
Message |
Steel Developer
Joined: 28 Dec 2007 Posts: 41 Location: Copenhagen, Denmark
|
Posted: Wed Mar 19, 2008 3:36 pm Post subject: |
|
|
I'm trying to play an mp3-file: beep.mp3
Winamp info box:
| Code: | Size: 3600 bytes
Header found at: 256 bytes
Length: 0 seconds
MPEG-1 layer 3
128kbit, approx. 8 frames
44100Hz Joint Stereo
CRCs: Yes, Copyrighted: No
Original: No, Emphasis: None |
Code:
| Java: | mBeeper = MediaPlayer.create(this, R.raw.beep);
mBeeper.setOnErrorListener(new MediaPlayer.OnErrorListener() {
public void onError(MediaPlayer mediaPlayer, int what, int extra) {
Log.e(ACTIVITY_NAME, "MediaPlayer.onError: what=" + what + " extra=" + extra);
}
});
mBeeper.prepareAsync();
|
Output:
| Code: | | MediaPlayer.onError: what=1 extra=0 |
Now does anyone know what the hell 'what' means?
That is - does anyone have any idea about the meaning of these method params, what and extra?
_________________ Eclipse is a fork, IntelliJ is the ninja sword. Which weapon are you going into battle with? |
|
| Back to top |
|
 |
JaydeRyu Freshman
Joined: 16 Mar 2008 Posts: 4
|
Posted: Thu Mar 20, 2008 12:57 am Post subject: |
|
|
| Steel wrote: | I'm trying to play an mp3-file: beep.mp3
Winamp info box:
| Code: | Size: 3600 bytes
Header found at: 256 bytes
Length: 0 seconds
MPEG-1 layer 3
128kbit, approx. 8 frames
44100Hz Joint Stereo
CRCs: Yes, Copyrighted: No
Original: No, Emphasis: None |
Code:
| Java: | mBeeper = MediaPlayer.create(this, R.raw.beep);
mBeeper.setOnErrorListener(new MediaPlayer.OnErrorListener() {
public void onError(MediaPlayer mediaPlayer, int what, int extra) {
Log.e(ACTIVITY_NAME, "MediaPlayer.onError: what=" + what + " extra=" + extra);
}
});
mBeeper.prepareAsync();
|
Output:
| Code: | | MediaPlayer.onError: what=1 extra=0 |
Now does anyone know what the hell 'what' means?
That is - does anyone have any idea about the meaning of these method params, what and extra? |
I would suggest
| Java: |
try{
mBeeper = MediaPlayer.create(this, R.raw.beep);
mBeeper.prepareAsync();
}catch(IOException e){
Log.e(_YOURTAG, _YOURINFO, e)
}
|
I couldn't find any details on the errors listed from the onErrorListener().
I don't know if this will help, but I found using
MediaPlayer.create(this, R.raw.beep);
to
MediaPlayer.create(YOUR_CLASS.this, R.raw.RESOURCE);
if it's a mp.prepareAsync() then i'm nor sure what problem is.
|
|
| Back to top |
|
 |
markww Freshman
Joined: 24 Feb 2008 Posts: 4
|
Posted: Thu Mar 20, 2008 1:00 am Post subject: |
|
|
Although the media player may be able to play a single sound one time, it still means it's unusable for any application that hopes to make any serious use of sound. You don't know when the sound has stopped, you can't tell how many times you'll be able to play the sound before the player crashes. I still haven't seen any solid solution on this, I've decided to ignore use of the media player until it's fixed in some distant android release. If anyone DOES have a complete solution, that'd be great to know of.
Thanks
|
|
| Back to top |
|
 |
Steel Developer
Joined: 28 Dec 2007 Posts: 41 Location: Copenhagen, Denmark
|
Posted: Thu Mar 20, 2008 1:10 am Post subject: |
|
|
Thanks for the reply, JaydeRyu.
prepare() throws an IOException - I tried that one first, but there was no explanation-text with the IOException. That's why I tried prepareAsync(), because then you can attach an OnErrorListener, which at least gives the clue, that what was wrong ... was 1
I'm creating & preparing the MediaPlayer in my onCreate() in my main Activity, so specifying the class name in front of this should be redundant, but I'll try it anyway ...
_________________ Eclipse is a fork, IntelliJ is the ninja sword. Which weapon are you going into battle with? |
|
| Back to top |
|
 |
JaydeRyu Freshman
Joined: 16 Mar 2008 Posts: 4
|
|
| Back to top |
|
 |
Steel Developer
Joined: 28 Dec 2007 Posts: 41 Location: Copenhagen, Denmark
|
Posted: Wed Apr 02, 2008 10:31 am Post subject: |
|
|
LOL, you were right, JaydeRyu: Don't prepare the MediaPlayer (like the manual says), just start it.
And to replay a sound, re-create the MP - you can't use the same object, which already played the sound. Wierd.
_________________ Eclipse is a fork, IntelliJ is the ninja sword. Which weapon are you going into battle with? |
|
| Back to top |
|
 |
zengcity Once Poster
Joined: 05 May 2008 Posts: 1
|
Posted: Mon May 05, 2008 6:04 pm Post subject: |
|
|
I met the NullPointerException too.
And I change the <Button id="@+id/cmd_play" to <Button android:id="@+id/cmd_play" in the "main.xml" file.
It works.
Hope it helps;
|
|
| Back to top |
|
 |
irobot Freshman
Joined: 27 Mar 2008 Posts: 2 Location: Coimbatore, India
|
Posted: Wed May 07, 2008 8:09 am Post subject: |
|
|
| zaac wrote: | Yes it is the solution but now i have an other bug when i click on the button play:
|
I have tried prepareAsync() instead of prepare() and it works fine.
_________________ If at first you don't succeed, look in the trash for the instructions. |
|
| Back to top |
|
 |
marielisacr Junior Developer
Joined: 21 May 2008 Posts: 12
|
Posted: Wed May 21, 2008 10:52 pm Post subject: |
|
|
Hi, i am trying to do a media player in android. Now i can play songs from an URL, i download the .mp3 file to a temp file and play it. The problem is that after listening a few songs the emulator crashes and restart by it itselft, it doesn´t show any error.
If anyone can help i really appreciate, thanks
|
|
| Back to top |
|
 |
Steel Developer
Joined: 28 Dec 2007 Posts: 41 Location: Copenhagen, Denmark
|
Posted: Wed May 21, 2008 11:21 pm Post subject: |
|
|
| marielisacr wrote: | Hi, i am trying to do a media player in android. Now i can play songs from an URL, i download the .mp3 file to a temp file and play it. The problem is that after listening a few songs the emulator crashes and restart by it itselft, it doesn´t show any error.
If anyone can help i really appreciate, thanks |
That sounds like the same problem markww described - that the emulator just crashes without errors after playing media sometimes. Wait for a new release
_________________ Eclipse is a fork, IntelliJ is the ninja sword. Which weapon are you going into battle with? |
|
| Back to top |
|
 |
sreekanth Once Poster
Joined: 03 Jun 2008 Posts: 1
|
Posted: Tue Jun 03, 2008 1:25 pm Post subject: regarding sound in musicplayer |
|
|
Hi,
I am running the musicplayer on my android.I am using fedora 7 and android m5.In my system the programme is running normally but the sound is not coming.I am sending my musicplayer.java and main.xml......
package com.google.android.musicplayer;
import java.io.IOException;
import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class musicplayer extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
Button cmd_play=(Button)this.findViewById(R.id.cmd_play);
cmd_play.setOnClickListener(new OnClickListener(){
//@Override
public void onClick(View arg0) {
// MediaPlayer mp=MediaPlayer.create(musicplayer.this,R.raw.santosam4);
MediaPlayer mp=new MediaPlayer();
try {
Toast.makeText(musicplayer.this, R.string.musicopen,
Toast.LENGTH_SHORT).show();
mp.setDataSource("/root/lion.wav");
mp.prepareAsync();
mp.start();
}catch(IOException e) {
Log.e("ioexception","",e);
}
Toast.makeText(musicplayer.this, R.string.musicopen,
Toast.LENGTH_SHORT).show();
mp.setOnCompletionListener(new OnCompletionListener(){
//@Override
public void onCompletion(MediaPlayer arg0){
Toast.makeText(musicplayer.this, R.string.musicclose,
Toast.LENGTH_SHORT).show();
}
});
}
});
}
}
main.xml
−
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Hello World, musicplayer"/>
<Button android:id="@+id/cmd_play" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="play the music ...."/>
</LinearLayout>
Regards,
Sreekanth.
| Description: |
|
| Filesize: |
57.21 KB |
| Viewed: |
427 Time(s) |

|
|
|
| Back to top |
|
 |
drik_wen Freshman
Joined: 12 Jul 2008 Posts: 3
|
Posted: Sun Jul 13, 2008 3:13 pm Post subject: playing media(mp3) from the URL problem |
|
|
I try to play a mp3 file from the URL..
but the song will also stop buffering after 31%..
so I always fail to play the mp3 file
is there someone can tell me why?? a lil bit hurry..
thx in advanced
|
|
| Back to top |
|
 |
mike_lee Once Poster
Joined: 12 Jul 2008 Posts: 1
|
Posted: Sun Jul 13, 2008 11:38 pm Post subject: Re: regarding sound in musicplayer |
|
|
I have the same problem here using fedora 8.
I can not hear sound, even if I hit the volume up/down button on emulator.
However, I can hear the mp3 using other mp3 player on my system.
does anyone have any clue on that?
Thanks a lot in advance
-sincerely
mike
| sreekanth wrote: | Hi,
I am running the musicplayer on my android.I am using fedora 7 and android m5.In my system the programme is running normally but the sound is not coming.I am sending my musicplayer.java and main.xml......
package com.google.android.musicplayer;
import java.io.IOException;
import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class musicplayer extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
Button cmd_play=(Button)this.findViewById(R.id.cmd_play);
cmd_play.setOnClickListener(new OnClickListener(){
//@Override
public void onClick(View arg0) {
// MediaPlayer mp=MediaPlayer.create(musicplayer.this,R.raw.santosam4);
MediaPlayer mp=new MediaPlayer();
try {
Toast.makeText(musicplayer.this, R.string.musicopen,
Toast.LENGTH_SHORT).show();
mp.setDataSource("/root/lion.wav");
mp.prepareAsync();
mp.start();
}catch(IOException e) {
Log.e("ioexception","",e);
}
Toast.makeText(musicplayer.this, R.string.musicopen,
Toast.LENGTH_SHORT).show();
mp.setOnCompletionListener(new OnCompletionListener(){
//@Override
public void onCompletion(MediaPlayer arg0){
Toast.makeText(musicplayer.this, R.string.musicclose,
Toast.LENGTH_SHORT).show();
}
});
}
});
}
}
main.xml
−
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Hello World, musicplayer"/>
<Button android:id="@+id/cmd_play" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="play the music ...."/>
</LinearLayout>
Regards,
Sreekanth. |
|
|
| Back to top |
|
 |
marielisacr Junior Developer
Joined: 21 May 2008 Posts: 12
|
Posted: Mon Jul 14, 2008 2:56 pm Post subject: |
|
|
Hi all,
There is a really good tutorial of how to play music from an Url here
http://www.anddev.org/viewtopic.php?p=8319#8319.
Try that and i hope you can solve your problems, it works for me.
I was capable to play sound in windows an Mac but I haven't try it on Linux.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
© 2007, Android Development Community
All rights reserved.
Powered by phpBB.
|