Thursday, April 26, 2012

[android-developers] MediaPlayer Prepare failed: status=0x1

Hi Android geeks.

I am having a practice writing a little audio player. The app connect
to http server to download mp3 files(not audio streaming). After
downloading, it player the file using mediaplayer. But I tried to
play it, error like title happens. Below is some pieces of my code:

public class ViewArticleActivity extends Activity {

MediaPlayer mediaPlayer;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView (R.layout.activity_view_article);

mediaPlayer = new MediaPlayer();
}

protected void downloadAudio(String url){
HttpDownload download = new HttpDownload(this, new
HttpDownloadListener(){
ProgressDialog mProgress;
public void onStart() {
Resources res = getResources();
mProgress = ProgressDialog.show(ViewArticleActivity.this,
res.getString(R.string.download),
res.getString(R.string.wait_download));
}

public void onDone(String filePath) {
mProgress.dismiss();

if (filePath==null){
Log.e(TAG, "File is null");
return;
}

File f = new File(filePath);
if (!f.exists()){
Log.e(TAG, "File not found:" + filePath);
return;
}

try {

//DB Access code will be here

mediaPlayer.setDataSource(filePath);
mediaPlayer.prepare(); //==> Error here

} catch (Exception e) {
Toast.makeText(ViewArticleActivity.this, e.getMessage(),
Toast.LENGTH_LONG).show();
}

}

});

download.download(url, "mypackage");
}

}

I can see the audio file in the file explorer, which is normal audio
file. But when I try to play the file, the error occurs. In the API
documentation, setDataSource(String path) accepts file path of a file
as parameter. I don't know what the problem is. Please help me...

Thanks in advance.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate