video viewing problem

by manoj » Thu, 05 Mar 2009 21:49:56 GMT

Sponsored Links

I have written the following code which plays the media file(.mp4).
Its working fine but,

I have two problems:
1. While trying to play a video file for the first time, video is not
getting played but the audio is playing(audible). Now if i try to play
the same video again in the application or if i restart the phone
(switch off and on ) i can see both video playing as well as the

2. I can play video if it is h.264 format. but if the video is of
encoding mpeg4, the app is unable to play the video.

can any one please suggest me to solve these two problems.

public class MediaPlayerDemo_Video extends Activity implements
MediaPlayer.OnPreparedListener, SurfaceHolder.Callback {

private static final String TAG = "MediaPlayerDemo";
private int mVideoWidth;
private int mVideoHeight;
private MediaPlayer mMediaPlayer;
private SurfaceView mPreview;
private SurfaceHolder holder;
private String path;
private Bundle extras;
private static final String MEDIA = "media";
private static final int LOCAL_AUDIO = 1;
private static final int STREAM_AUDIO = 2;
private static final int RESOURCES_AUDIO = 3;
private static final int LOCAL_VIDEO = 4;
private static final int STREAM_VIDEO = 5;

* Called when the activity is first created.
public void onCreate(Bundle icicle) {
mPreview = (SurfaceView) findViewById(;
holder = mPreview.getHolder();
extras = getIntent().getExtras();


private void playVideo(Integer Media) {
try {

switch (Media) {
* TODO: Set the path variable to a local media
file path.
path = "";
if (path == "") {
// Tell the user to provide a media file URL.
"Please edit
MediaPlayerDemo_Video Activity, "
+ "and set the path
variable to your media file path."
+ " Your media file
must be stored on sdcard.",

* TODO: Set path variable to progressive
streamable mp4 or
* 3gpp format URL. Http protocol should be used.
* Mediaplayer can only play "progressive
* contents" which basically means: 1. the movie
atom has to
* precede all the media data atoms. 2. The clip
has to be
* reasonably interleaved.

path = extras.getString("MediaFileName&quo

Other Threads

1. Upgrading code to 2.1

Hi there,

I have a widget which I developed using the 1.5 SDK, I am now looking
to make the necessary changes to make it work on 2.1. I have read the
docs regarding this and I have set my manifest as  <uses-sdk
android:minSdkVersion="3" /> so that it can be used from 3 upwards.
What is unclear to me is about breaking code, for example as of 1.5 I
override onStart() method in my service, but that method is deprecated
in newer versions and it has become onStartCommand(), so how a phone
running a newer OS is going to behave there?
The same occurs if I compile it with 2.1 then phones on 1.5 will not
know anything about onStartCommand().

Or did I get the whole thing wrong?


2. Get name of current ring tone

Hi i'm using the following method to set a ringtone

public void setRingTone(Context context){
                        String filepath ="/sdcard/schoolbell.mp3";
                        File ringtoneFile = new File(filepath);

                        Log.d(LOG_TAG,"Starting content puts");
                        ContentValues content = new ContentValues();
                        //content.put(MediaStore.MediaColumns.SIZE, 215454);
                        //content.put(MediaStore.Audio.Media.ARTIST, "Madonna");
                        //content.put(MediaStore.Audio.Media.DURATION, 230);
                        content.put(MediaStore.Audio.Media.IS_RINGTONE, true);
                        //content.put(MediaStore.Audio.Media.IS_ALARM, false);
                        //content.put(MediaStore.Audio.Media.IS_MUSIC, false);

                        Log.d(LOG_TAG,"Starting database puts");
                        //Insert it into the database
                        Log.i(LOG_TAG, "the absolute path of the file
is :"+ringtoneFile.getAbsolutePath());
                        Uri uri = MediaStore.Audio.Media.getContentUriForPath
                        Uri newUri = context.getContentResolver().insert(uri, 
                        Uri ringtoneUri = newUri;
                        Log.i(LOG_TAG,"1 the ringtone uri is :"+uri);
                        Log.i(LOG_TAG,"2 the ringtone uri is :"+ringtoneUri);

                        catch (Exception e)
                        {Log.e(LOG_TAG,"Error @3:"+e.getMessage());}

It works perfectly except i only want it to add the tone if it hasent
been added already, is there any way to get the name of the current
ringtone so i can compare it to the file i want to set as my ring
tone? or another way of doing it?
Any help would be great. Thank you

3. How to navigate from one page to another?

4. capturing the encoded audio data read by the PV

5. how can i make any service running when the phone is switched on just after the booting.

6. Porting android on a AT91SAM9G20 with 64MByte of RAM and 8MByte dataflash memory

7. Getting hold of a resource using generated string