video viewing problem

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


Sponsored Links
 i,

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
audio.

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.OnBufferingUpdateListener,
MediaPlayer.OnCompletionListener,
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) {
super.onCreate(icicle);
setContentView(R.layout.mediaplayer_2);
mPreview = (SurfaceView) findViewById(R.id.surface);
holder = mPreview.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
extras = getIntent().getExtras();

}

private void playVideo(Integer Media) {
try {

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

}
break;
case STREAM_VIDEO:
/*
* TODO: Set path variable to progressive
streamable mp4 or
* 3gpp format URL. Http protocol should be used.
* Mediaplayer can only play "progressive
streamable
* 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. Market Question

I have a question related to the payment infrastructure. I have an
application similar to the iTunes. The application is installed from
the arketbut the songs are downloaded from my side and charges are
applied to every song download. I would prefer to make the songs
available through the Market so the Market manages all  the charges
but I don see how. Anybody else works on the same scenario?

2. adjustResize with Landscape Mode.

Hello All,
I have an application which has the main layout(main.xml)  as given
below.

<RelativeLayout xmlns:android=" http://www.***.com/ 
android"
    android:id="@+id/main"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
   >
<TextView android:layout_alignParentTop="true" android:id="@+id/
txtView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
<TextView android:layout_width="fill_parent"  android:gravity="bottom"
android:id="@+id/txtView2"
        android:layout_alignParentBottom="true"
    android:layout_height="wrap_content"
    android:text="Is this appearing @ bottom?"/>

  <LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"    android:layout_below="@id/
txtView1"
        android:layout_alignParentBottom="true"
android:orientation="vertical">
        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Check this m i{*filter*} one two three four five six
"/>

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Check this m i{*filter*}2 seven eight nine ten"/>

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Check this m i{*filter*}3 one two three four five six
"/>

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Check this m i{*filter*}4 seven eight nine ten"/>

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Check this m i{*filter*}5 one two three four five six
"/>

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Check this m i{*filter*}6 seven eight nine ten"/>
        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="7 Seven"/>

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="8 Eight"/>

  </LinearLayout>

</RelativeLayout>

i have an Activity which uses the above layout to set its content
View. This Activity is configured in the Manifest file to have
android:windowSoftInputMode="adjustResize". Now when i am in Portrait
mode the softkeyboard pops-up and the text "Is this appearing @
bottom?" (ie) the textView (android:id="@+id/txtView2") appears just
above the softkeyboard with the other text overwritten over it as they
fall from top to bottom.

Now when i flip the phone to landscape mode this behaviour is changed
and it behaves as defined in property "adjustUnspecified" . Is this a
bug? How can i have "adjustResize" behaviour in landscape mode? What
is the workaround in this scenario?

I have already read the post
 http://www.***.com/ ;q=adjustResize+in+landscape#e018c53962cacd7b
and the screen doesn't move to full-screen as i have only a Text View.
(I have a specific requirement to have it that way). FYI i use the
default IME and using Android 2.1 on a HTC phone with no external
keyboard.

Regards
V. Ramkumar.


-- 

3. ExpandableListView help

4. Application restarts on orientation change

5. Developing games for Galaxy Tab

6. Splash screen | warning: Activity not started, its current task has been brought to the front

7. Download large file from network to SD card