| Author |
Message |
bdodson Once Poster

Joined: 31 Oct 2008 Posts: 1
|
Posted: Fri Oct 31, 2008 6:46 pm Post subject: |
|
|
Thanks for the tutorial.. Does anyone know the best way to get a playlist (m3u) file to play? I'm hoping to avoid dealing with playback issues like fwd/rew/pause etc, I just want to send the media player a list of files to play...
By default, the web browser doesn't seem to be able to handle an m3u file correctly. |
|
| Back to top |
|
 |
|
|
 |
VoiceTech Freshman

Joined: 02 Dec 2008 Posts: 3
|
Posted: Sun Dec 21, 2008 1:25 pm Post subject: Re: regarding sound in musicplayer |
|
|
| mike_lee wrote: | 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. |
|
In your run configuration make sure you have:
-audio oss
According to the documentation the -useaudio parameter is enabled by default so you shouldn't need it.
Also, what threw me was the exception when using prepare(). Just use:
try {
mp = MediaPlayer.create(PlayMusic.this, R.raw.groovytune);
mp.start();
} catch (IllegalStateException e) {
e.printStackTrace();
}
You will need to call prepare() if you are looking to play the media file again.
Instructions for -useaudio and -audio here:
http://code.google.com/android/reference/emulator.html#startup-options
Instructions on how to use the media player here:
http://code.google.com/android/toolbox/apis/media.html
I'm running CentOS 5.2 with SDK 1.0 sr2.
Hope this helps! |
|
| Back to top |
|
 |
andreleitao Experienced Developer

Joined: 10 Mar 2009 Posts: 55 Location: Recife - Brazil
|
Posted: Fri Apr 03, 2009 7:32 pm Post subject: |
|
|
Hi, why when I call mediaplayer.stop() or mediaplayer.pause() is continues playing the sound?
E.g.:
| Java: |
mediaplayer = MediaPlayer.create(MainActivity.getInstance(), R.raw.musicmp3);
try {
mp.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mp.start();
|
If I call mediaplayer.stop() the music is not stopped. Why that?
Thanks! |
|
| Back to top |
|
 |
lostInTransit Developer

Joined: 12 Feb 2009 Posts: 26 Location: India
|
Posted: Sat May 23, 2009 6:24 am Post subject: |
|
|
Reviving an old thread. I needed some help with the MediaPlayer class
I am using a MediaPlayer instance in order to stream audio files from an Internet location. The audio player is in a separate activity. The user can select from a list of audio files and come to this activity to play the audio.
Now the user might go back to the previous activity (with the list) and select another audio file. In this case, I want to stop any other audio that is playing and start playing the new audio which was selected.
I did find out how to know whether an audio is playing. We can do it by using an object of AudioManager and calling isAudioPlaying(). This will return a true if any audio is playing.
How do I stop an audio currently playing? I do not have an instance of the MediaPlayer object which was created to start the audio (coz the user has already left the activity once and has come back with a new object of the activity and thus a new instance of the MediaPlayer). Is there any way I can stop any audio playing without having to hold on to the MediaPlayer object?
Thanks. |
|
| Back to top |
|
 |
exospy Freshman

Joined: 08 Jun 2009 Posts: 4 Location: San Francisco
|
Posted: Mon Jun 08, 2009 11:20 pm Post subject: |
|
|
When I try to use the -useaudio at the command line in eclipse, i continue getting an error:
[2009-06-08 17:16:26 - Emulator] unknown option: -useaudio
[2009-06-08 17:16:26 - Emulator] please use -help for a list of valid options
Anyone with suggestions? i have android 1.5 with eclipse but i get this error. really frustrated. |
|
| Back to top |
|
 |
exospy Freshman

Joined: 08 Jun 2009 Posts: 4 Location: San Francisco
|
Posted: Tue Jun 09, 2009 12:10 am Post subject: |
|
|
my issue is this...
-useaudio i assume is not recognized anymore? someone confirm that for me? i used "-audio <name of sound sytem>", in my cause "-audio winaudio"
hope this helps others who have the same problem. |
|
| Back to top |
|
 |
|
|
 |
vaibhavm Freshman

Joined: 01 Jul 2009 Posts: 3
|
Posted: Wed Jul 01, 2009 9:53 am Post subject: how to progress on Seekbar |
|
|
Hi,
Dose any one know how to show progress of audio file which is being played on a seekbar or progress bar
thanks in advance |
|
| Back to top |
|
 |
llt1214 Freshman

Joined: 05 May 2009 Posts: 5
|
Posted: Tue Aug 11, 2009 10:08 am Post subject: |
|
|
| lostInTransit wrote: | Reviving an old thread. I needed some help with the MediaPlayer class
I am using a MediaPlayer instance in order to stream audio files from an Internet location. The audio player is in a separate activity. The user can select from a list of audio files and come to this activity to play the audio.
Now the user might go back to the previous activity (with the list) and select another audio file. In this case, I want to stop any other audio that is playing and start playing the new audio which was selected.
I did find out how to know whether an audio is playing. We can do it by using an object of AudioManager and calling isAudioPlaying(). This will return a true if any audio is playing.
How do I stop an audio currently playing? I do not have an instance of the MediaPlayer object which was created to start the audio (coz the user has already left the activity once and has come back with a new object of the activity and thus a new instance of the MediaPlayer). Is there any way I can stop any audio playing without having to hold on to the MediaPlayer object?
Thanks. |
Hi lostInTransit! Have you already found the solution to this problem? I was also trying to stop a currently playing audio from a different application.
Thanks. |
|
| Back to top |
|
 |
shishir.bobby Experienced Developer

Joined: 09 Apr 2009 Posts: 59
|
Posted: Fri Sep 04, 2009 7:27 am Post subject: |
|
|
| andreleitao wrote: | Hi, why when I call mediaplayer.stop() or mediaplayer.pause() is continues playing the sound?
E.g.:
| Java: |
mediaplayer = MediaPlayer.create(MainActivity.getInstance(), R.raw.musicmp3);
try {
mp.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mp.start();
|
If I call mediaplayer.stop() the music is not stopped. Why that?
Thanks! |
here is my code, in this, u can play,pause and stop d song,its for a single song,no playlist implemented yet ...remember to change the path of song...and try my code...and try to implement itin ur code
| Java: |
package com.shishir;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
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);
final MediaPlayer mplayer = MediaPlayer.create(MusicPlayer.this,
R.raw.linkinpark);
// PLAY button
Button play = (Button) this.findViewById(R.id.play);
play.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// mp.prepare();
mplayer.start();
mplayer.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer arg0) {
// End of file
}
});
}
});
// PAUSE button
Button pause = (Button) this.findViewById(R.id.pause);
pause.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
mplayer.pause();
}
});
// STOP button
Button stop = (Button) this.findViewById(R.id.stop);
stop.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
mplayer.stop();
}
});
}
}
|
my main.xml
| XML: |
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget35"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<Button
android:id="@+id/play"
android:layout_width="64px"
android:layout_height="wrap_content"
android:text="PLAY"
android:layout_x="0px"
android:layout_y="0px"
>
</Button>
<Button
android:id="@+id/pause"
android:layout_width="64px"
android:layout_height="wrap_content"
android:text="PAUSE"
android:layout_x="125px"
android:layout_y="5px"
>
</Button>
<Button
android:id="@+id/stop"
android:layout_width="65px"
android:layout_height="wrap_content"
android:text="STOP"
android:layout_x="255px"
android:layout_y="2px"
>
</Button>
</AbsoluteLayout>
|
thanks and regards |
|
| Back to top |
|
 |
marcjc Junior Developer

Joined: 05 Jan 2010 Posts: 11
|
Posted: Wed Jan 06, 2010 7:34 pm Post subject: |
|
|
Your code is great.... thanks.... 1 question though..
After stopping a song from playing, how do you restart the song? I click play again and it does not start. I have to exit and then restart to play.
thank you again. |
|
| Back to top |
|
 |
perrot Junior Developer

Joined: 22 Jan 2010 Posts: 10 Location: China
|
Posted: Fri Jan 22, 2010 3:27 am Post subject: |
|
|
| marcjc wrote: | Your code is great.... thanks.... 1 question though..
After stopping a song from playing, how do you restart the song? I click play again and it does not start. I have to exit and then restart to play.
thank you again. |
play again.
try this:
MediaPlayer mp=new MediaPlayer();
//stop media player
mp.stop();
mp.reset();
//start media player
mp.start();
//pause media player
mp.pause();
 |
|
| Back to top |
|
 |
Anders Once Poster

Joined: 25 Jan 2010 Posts: 1
|
Posted: Mon Jan 25, 2010 6:49 pm Post subject: |
|
|
Hi, dont know if you guys made it work allready, but when you use MediaPlayer.Create();
you cant use prepare();, it is allready loaded on create....
so the right one is :
MediaPlayer mp = MediaPlayer.create(this, R.raw.sound);
mp.start();
Hope its helps..... |
|
| Back to top |
|
 |
marcjc Junior Developer

Joined: 05 Jan 2010 Posts: 11
|
Posted: Wed Feb 10, 2010 8:47 pm Post subject: |
|
|
all good now...
but now trying to add more than one song to play when the play button is pressed again....
example:
press button song plays, press button again, song 2 plays, press button again, song 3 plays, etc.... |
|
| Back to top |
|
 |
cfultz Once Poster


Joined: 12 Feb 2010 Posts: 1 Location: Virginia
|
|
| Back to top |
|
 |
ropiemasta Once Poster

Joined: 27 Feb 2010 Posts: 1
|
Posted: Tue Mar 02, 2010 6:29 pm Post subject: |
|
|
| Quote: |
package com.shishir;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
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);
final MediaPlayer mplayer = MediaPlayer.create(MusicPlayer.this,
R.raw.linkinpark);
// PLAY button
Button play = (Button) this.findViewById(R.id.play);
play.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// mp.prepare();
mplayer.start();
mplayer.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer arg0) {
// End of file
}
});
}
});
// PAUSE button
Button pause = (Button) this.findViewById(R.id.pause);
pause.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
mplayer.pause();
}
});
// STOP button
Button stop = (Button) this.findViewById(R.id.stop);
stop.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
mplayer.stop();
}
});
}
}
[/syntax]
|
So I used your code and everything works fine.. except when I want to play the file again... What do I need to add/change to make it so when I press "Play" after pressing "Stop" to get the mp3 to play from the begining again? The only way I've been able to is to restart. I'm guessing it's because the mediaplayer is created during onCreate... Thanks for the help. |
|
| Back to top |
|
 |
|