You need to use

path = Environment.getExternalStorageDirectory() +"/1.mp3"

On Mar 11, 7:45 am, Yash Jain <[email protected]> wrote:
> Hello All,
> I am new to java and android Apps.
> Basically i want to test weather a media file can be played on my mobile
> device so to do this i wanted to write android application which does play a
> media file and if it fails then it throws an error.
>
> I tried writing an application which will playback from a file 1.mp3 stored
> on my SDCard, but i am not able to execute it on a mobile.
> Please find the sample code below,
>
> package com.example.helloandroid;
>
> import android.app.Activity;
> import android.os.Bundle;
> import android.widget.TextView;
> import android.media.MediaPlayer;
> import java.io.IOException;
>
> public class HelloAndroid extends Activity {
>     /** Called when the activity is first created. */
>     private MediaPlayer     mPlayer;
>     public String path = "\1.mp3";
>
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         TextView tv = new TextView(this);
>         setContentView(tv);
>         mPlayer = new MediaPlayer();
>         try {
>             mPlayer.setDataSource(path);
>             mPlayer.prepare();
>             mPlayer.start();
>         } catch (IOException e) {
>             tv.setText("Error Creating media Player");
>         }
>
>     }
>
> }
>
> Please let me know , if i am on a right direction.
>
> Any tutorial or a sample code to playback a video/audio file stored on a
> SDCard will be helpful.
>
> Thanks and Regards,
> Yeshpal Jain.

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

Reply via email to