play video for android eclipse

Video.java
//Implement SurfaceHolder interface to Play video
//Implement this interface to receive information about changes to the surface
public class VideoPlayerbokeh extends Activity implements SurfaceHolder.Callback{

MediaPlayer mediaPlayer;
SurfaceView surfaceView;
SurfaceHolder surfaceHolder;
boolean pausing = false;;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video);

Button buttonPlayVideo = (Button)findViewById(R.id.playvideoplayer);

getWindow().setFormat(PixelFormat.UNKNOWN);

//Displays a video file.
VideoView mVideoView = (VideoView)findViewById(R.id.videoview);

//String myip=ip.getIP();
//String uriPath = myip+”http://192.168.43.10/videopendaki/bubble.MP4″;

String uriPath = “android.resource://com.android.AndroidVideoPlayer/”+R.raw.k;
Uri uri = Uri.parse(uriPath);
mVideoView.setVideoURI(uri);
mVideoView.requestFocus();
mVideoView.start();

buttonPlayVideo.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
VideoView mVideoView = (VideoView)findViewById(R.id.videoview);
// VideoView mVideoView = new VideoView(this);
// String uriPath = “http://192.168.43.10/videopendaki/bubble.MP4”;
String uriPath = “android.resource://com.android.AndroidVideoPlayer/”+R.raw.k;//k adalah nama video yg ada di folder raw
Uri uri = Uri.parse(uriPath);
mVideoView.setVideoURI(uri);
mVideoView.requestFocus();
mVideoView.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

}
}

 

video.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”
>
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”

/>
<Button
android:id=”@+id/playvideoplayer”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”- PLAY Video -”
/>

<VideoView
android:id=”@+id/videoview”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
/>

</LinearLayout>jasa pembuatan program skripsi dan tugas akhir

× Konsultasi Sekarang