• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Audio file + mediaplayer error (1, -4)

ocampesato

Lurker
Feb 17, 2010
2
0
Hello,

AFAIK this problem is not posted anywhere on this forum. I would like to play a short audio file (see short code sample below) in Android 2.x, and I encounter this error message:
mediaplayer error (1, -4).

This is what I found in one entry (after a Google search):
"-4 is PVMFErrNotSupported, which also seems to be a catch-all that
usually occurs during prepare() and probably means that OpenCore found
something it didn't like in the stream."

Btw, the audio files play fine from the command line, which launches the Windows Media Player (Windows Vista). I'm sure that there is a very simple solution;(

Suggestions welcome...
Oswald

=====================================================
package oac.graphics;
import java.io.IOException;
import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
public class PlaySound extends Activity
{
// Called when the activity is first created
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(new SimpleView(this));
}
private static class SimpleView extends View
{
private MediaPlayer mediaPlayer = null;
//private String mediaFile = "/assets/abc.wmv";
//private String mediaFile = "./assets/abc.wav";
//private String mediaFile = "./assets/abc.mp3";
private String mediaFile = "abc.mp3";

public SimpleView(Context context)
{
super(context);
setFocusable(true);
playSound(context);
}

private void playSound(Context context)
{
try {
mediaPlayer = new MediaPlayer();

if(mediaPlayer != null)
{
mediaPlayer.setDataSource(mediaFile);
mediaPlayer.prepare();
mediaPlayer.start();
mediaPlayer.pause();
mediaPlayer.stop();
}
}
catch(IllegalArgumentException iae) {
Log.i("media player exception: ", "IAE");
Log.w("media player exception: ", "IAE");
Log.e("media player exception: ", "IAE");
}
catch(IOException ioe) {
Log.i("media player exception: ", "IOE");
Log.w("media player exception: ", "IOE");
Log.e("media player exception: ", "IOE");
}
}
}
}
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones