ColorWPの助けを借りてこれを動作させたので(どうもありがとう)私は自分がしたことを投稿すると思いました:
これが私のxmlで、フレームレイアウトを使用してサムネイルと再生画像を重ね合わせています。
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="292dp"
android:layout_height="100dp"
android:layout_x="7dp"
android:layout_y="16dp"
android:text="" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="281dp"
android:layout_x="1dp"
android:layout_y="138dp"
>
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content">
<VideoView
android:id="@+id/svid"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<ImageView
android:id="@+id/simg"
android:layout_width="187dp"
android:layout_height="137dp"
android:src="@drawable/ic_action_search"
android:layout_centerInParent="true" />
<ImageView
android:id="@+id/playimg"
android:layout_width="100dp"
android:layout_height="87dp"
android:src="@drawable/animated_loading"
android:layout_centerInParent="true"
/>
</RelativeLayout>
</FrameLayout>
コードでは、再生画像にClickListenerを設定するだけだったので、ユーザーが画面で再生画像を押すと、video.start()を使用しました。それは完璧に機能しました:)
これが私のコードの抜粋です:
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.single);
vid=(VideoView) findViewById(R.id.svid);
iv=(ImageView) findViewById(R.id.simg);
ip=(ImageView) findViewById(R.id.playimg);
t=(TextView) findViewById(R.id.textView1);
final ProgressDialog pd=new ProgressDialog(SingleItem.this);
link="http://www.w3schools.com/html5/movie.mp4";
String path1=link;
MediaController mc = new MediaController(this);
mc.setAnchorView(vid);
mc.setMediaPlayer(vid);
uri=Uri.parse(path1);
vid.setMediaController(mc);
vid.setVideoURI(uri);
vid.requestFocus();
loadImage(thumb);
ip.setClickable(true);
ip.setImageResource(R.drawable.play);
// ip.setVisibility(ImageView.INVISIBLE);
vid.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
// TODO Auto-generated method stub
//ip.setVisibility(ImageView.VISIBLE);
pd.dismiss();
}
});
ip.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
vid.start();
pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pd.setMessage("Loading Video...");
pd.setIndeterminate(false);
pd.setCancelable(true);
pd.show();
if(vid.isPlaying()){
iv.setVisibility(ImageView.INVISIBLE);
ip.setVisibility(ImageView.INVISIBLE);
}else{
iv.setVisibility(ImageView.VISIBLE);
ip.setVisibility(ImageView.VISIBLE);
}
}
});
お役に立てれば :)