Problem with playing .ogg stream

All your problems with Audio, Video and Images.

Problem with playing .ogg stream

Postby fireblazt » Fri Oct 15, 2010 8:08 am

Hi all, I am new to this forum and java/android apps.

I have been reading allot lately and tried to make a app that plays a .ogg stream from the web.
The code that i have put togheter is this and Eclipse shows no error.

But when i start the app and push play, the stream dosen't play.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package app.stream;
  2.  
  3. import java.io.IOException;
  4. import android.app.Activity;
  5. import android.os.Bundle;
  6.  
  7. import android.media.MediaPlayer;
  8. import android.media.MediaPlayer.OnCompletionListener;
  9. import android.view.View;
  10. import android.view.View.OnClickListener;
  11. import android.widget.Button;
  12. import android.util.Log;
  13.  
  14.  
  15. public class AudioPlayerActivity extends Activity
  16. {
  17. /** Called when the activity is first created. */
  18. protected static final int PLAY = 0x101;
  19. protected static final int STOP = 0x102;
  20. protected static final int PAUSE = 0x103;
  21. int State;
  22.  
  23. public void onCreate(Bundle icicle) {
  24. super.onCreate(icicle);
  25. setContentView(R.layout.main);
  26.  
  27. final MediaPlayer mplayer = new MediaPlayer();
  28. mplayer.stop();
  29.  
  30. // PLAY button
  31. Button play = (Button) this.findViewById(R.id.cmd_play);
  32. State = STOP;
  33. play.setOnClickListener(new OnClickListener() {
  34. @Override
  35. public void onClick(View arg0) {
  36.  
  37. // mp.prepare();
  38. //mplayer.reset();
  39. if (State == STOP)
  40. {
  41. try
  42. {
  43.     mplayer.setDataSource("http://radio.hbr1.com:19800/trance.ogg");
  44.     mplayer.prepareAsync();
  45.     mplayer.start();
  46. }
  47. catch(IOException e)
  48. {
  49. Log.d("AudioPlayer","IOException");
  50. }
  51. }
  52. mplayer.start();
  53. State = PLAY;
  54. mplayer.setOnCompletionListener(new OnCompletionListener() {
  55. public void onCompletion(MediaPlayer arg0) {
  56.  
  57. }
  58. });
  59. }
  60. });
  61.  
  62. // PAUSE button
  63. Button pause = (Button) this.findViewById(R.id.cmd_pause);
  64. pause.setOnClickListener(new Button.OnClickListener() {
  65. public void onClick(View v) {
  66. mplayer.pause();
  67. State = PAUSE;
  68. }
  69. });
  70.  
  71. // STOP button
  72. Button stop = (Button) this.findViewById(R.id.cmd_stop);
  73. stop.setOnClickListener(new Button.OnClickListener() {
  74. public void onClick(View v) {
  75. mplayer.stop();
  76. State = STOP;
  77. }
  78. });
  79.  
  80. }
  81. }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4


Layout:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <AbsoluteLayout
  4.  
  5. android:id="@+id/widget35"
  6.  
  7. android:layout_width="fill_parent"
  8.  
  9. android:layout_height="fill_parent"
  10.  
  11. xmlns:android="http://schemas.android.com/apk/res/android"
  12. >
  13.  
  14. <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/fiveobg">
  15. <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Hello World, musicplayer" android:visibility="invisible"/>
  16. <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:minHeight="10px" android:maxHeight="20px" android:layout_marginTop="150px" android:id="@+id/cmd_play" android:text="Hør på politiradioen"/>
  17. <Button android:id="@+id/cmd_stop" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="20px" android:text="Stopp politiradioen"/>
  18. <Button android:id="@+id/cmd_pause" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="20px" android:text="Pause politiradioen"/>
  19.  
  20. <SeekBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:scrollbarStyle="insideOverlay" android:layout_marginTop="20px" android:layout_marginLeft="130px" android:id="@+id/cmd_volum" android:contentDescription="Volum" android:minWidth="340px" android:saveEnabled="true"></SeekBar>
  21. <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Volum" android:layout_marginTop="-35px" android:layout_marginLeft="30px"></TextView>
  22. </LinearLayout>
  23. </AbsoluteLayout>
Parsed in 0.006 seconds, using GeSHi 1.0.8.4
User avatar
fireblazt
Freshman
Freshman
 
Posts: 2
Joined: Thu Oct 14, 2010 7:05 am
Location: Molde, Norway

Top

Re: Problem with playing .ogg stream

Postby fireblazt » Tue Oct 19, 2010 7:18 am

Anyone have an idea on what could be wrong?
User avatar
fireblazt
Freshman
Freshman
 
Posts: 2
Joined: Thu Oct 14, 2010 7:05 am
Location: Molde, Norway

Re: Problem with playing .ogg stream

Postby djodjo » Wed Jan 12, 2011 10:33 pm

if you use prepareAsync()
you have to set setOnPreparedListener() which will fire when enough data is loaded for the palyer to start
for example:
mp.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
//We are starting to play Now!
mp.start();
}
});
_
if you want to fly look up in the sky /djodjo.org
djodjo
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Jan 12, 2011 10:22 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 10 guests