Hi All,

         I tried to run the media player coding as:

Sample.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<SurfaceView android:id="@+id/surface"
android:layout_width="fill_parent"
android:layout_height="250px"
android:layout_gravity="center">
</SurfaceView>
</LinearLayout>


Sample1.Java

package com.Test;

import java.io.IOException;

import android.app.Activity;
import android.graphics.PixelFormat;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.Button;
import android.widget.VideoView;

public class Sample1 extends Activity  implements
SurfaceHolder.Callback
{
        Button button=null;
        VideoView mVideoView;
        MediaPlayer mediaPlayer;
          private SurfaceView videoView;
            private SurfaceHolder videoHolder;
            Bundle extras;
    @Override
        public void onCreate(Bundle savedInstanceState)
    {
        getWindow().setFormat(PixelFormat.TRANSPARENT);
        videoView = (SurfaceView) findViewById(R.id.surface);
        videoHolder = videoView.getHolder();
        videoHolder.addCallback(this);
        videoHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        videoHolder.setFixedSize(videoView.getWidth(), 300);

        try {
                        playmedia("/root/test_cbr.mp3");
                } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
}
    private void playmedia(String songpath) throws
IllegalArgumentException, IllegalStateException, IOException {
        mediaPlayer = new MediaPlayer();
        mediaPlayer.setAudioStreamType(2);
        mediaPlayer.setDataSource(songpath);
        mediaPlayer.setDisplay(videoHolder);

        mediaPlayer.prepare();
        mediaPlayer.start();
        }
        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int
width,
                        int height) {
                // TODO Auto-generated method stub

        }
        @Override
        public void surfaceCreated(SurfaceHolder holder) {
                // TODO Auto-generated method stub

        }
        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
                // TODO Auto-generated method stub

        }
}


   I dont see any output in my screen. I see only blank screen.I want
to play the media file.Can any one tell me what is happening in my
code?.

Thanks,

Dhuri Natarajan.





--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" 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-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to