I have create a method for playing a video in a video player and called that method on a button click, but whenever I was click on the button then the activity page blink for a half second but the player wasn't appear on the screen. Plz help me Is there neccessary to crea开发者_Go百科te view or a layout for a video player for playing a video in xml file. I havn't create this.
import android.app.Activity;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.VideoView;
public class OptionsmenuAct extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button play =(Button)findViewById(R.id.video);
Equity.setOnClickListener(new OnClickListener(){
public void onClick(View V){
videoPlayer("/Optionsmenu/assets/lic.3gp","lic",true);
}
});}
public void videoPlayer(String path, String fileName,boolean autoplay){
getWindow().setFormat(PixelFormat.TRANSLUCENT);
VideoView videoHolder = new VideoView(this);
videoHolder.setMediaController(new MediaController(this));
videoHolder.setVideoURI(Uri.parse(path+"/"+fileName));
videoHolder.requestFocus();
videoHolder.start();
if(autoplay){
videoHolder.start();
}
}
}
Plz tell me how's it will worked. I have store my video file into assets folder.
You can use VideoView. See example of usage here.
Adding VideoView to layout XML file is as any other component, for example (taken from android site):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<VideoView
android:id="@+id/surface_view"
android:layout_width="320px"
android:layout_height="240px"
/>
</LinearLayout>
精彩评论