android code for code play video :
This Application are 2.3.3 target
----------------------------------------------------
package com.myandroid.vedioPlayer;
import android.app.Activity;
import android.graphics.PixelFormat;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.VideoView;
public class VedioPlayActivity extends Activity
{
Button btPlay;
VideoView vv;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btPlay=(Button)findViewById(R.id.button1);
vv=(VideoView)findViewById(R.id.videoView1);
btPlay.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
palyVideo();
}
private void palyVideo()
{
getWindow().setFormat(PixelFormat.TRANSLUCENT);
VideoView videoHolder = new VideoView(VedioPlayActivity.this);
videoHolder.setMediaController(new MediaController(VedioPlayActivity.this));
Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.test);
videoHolder.setVideoURI(video);
setContentView(videoHolder);
videoHolder.start();
}
});
}
}
//////////////////////////////////////XML////////////////////////////////
main.xml
-----------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PLAY" />
<VideoView
android:id="@+id/videoView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
-------------------------------------------------------------------------------------
create raw folder in res and put video file
for example here test.3gp
No comments:
Post a Comment