Android MediaPlayer Problems :”Error (-38 , 0) ” and “stop called in state 1”

Before prepare(), you need first to call setDataSource(..). The Media framework is a very strict state machine, and it’s really cumbersome to handle all the different states. I’ve used this little wrapper that makes the coding/debugging a bit easier. You can give it a try. Regarding emulator – note that not all file formats are … Read more

how to play audio file in android

Simply you can use MediaPlayer and play the audio file. Check out this nice example for playing Audio: public void audioPlayer(String path, String fileName){ //set up MediaPlayer MediaPlayer mp = new MediaPlayer(); try { mp.setDataSource(path + File.separator + fileName); mp.prepare(); mp.start(); } catch (Exception e) { e.printStackTrace(); } }

Online radio streaming app for Android

So I found this sample and it works for me, here it is if you have the same issue: in myMain.java import android.app.Activity; import android.os.Bundle; import java.io.IOException; import android.media.MediaPlayer; import android.media.MediaPlayer.OnBufferingUpdateListener; import android.media.MediaPlayer.OnPreparedListener; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ProgressBar; public class myMain extends Activity implements OnClickListener { private ProgressBar playSeekBar; private … Read more

How do I play an mp3 in the res/raw folder of my android app?

When starting the activity i.e on onCreate put the following code. public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); MediaPlayer mPlayer = MediaPlayer.create(FakeCallScreen.this, R.raw.mysoundfile); mPlayer.start(); } When stopping the activity i.e on onDestroy put the following code. public void onDestroy() { mPlayer.stop(); super.onDestroy(); } Hope it helps 🙂

How do I use Android ProgressBar in determinate mode?

use the style ?android:attr/progressBarStyleHorizontal for example: <ProgressBar android:id=”@+id/progressBar” style=”?android:attr/progressBarStyleHorizontal” and this is an example with MediaPlayer: package com.playerpgbar; import android.app.Activity; import android.media.MediaPlayer; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; public class Player extends Activity implements Runnable, OnClickListener { private TextView status; private ProgressBar progressBar; private Button startMedia; private Button stop; … Read more

JavaFX: “Toolkit” not initialized when trying to play an mp3 file through MediaPlayer class

JavaFX performs “hidden” initialization on start. Running MediaPlayer doesn’t trigger initialization. The easiest ways to trigger it are: have Application.launch() executed have Application based program being run from jar packaged by fx ant tasks (e.g. built from Netbeans JavaFX project) have JFXPanel started call Platform.startup(Runnable) (Java 9+)