Button btn1 = (Button)findViewById(R.id.button); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final VideoView myVideoV = (VideoView)findViewById(R.id.videoView); myVideoV.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.a1)); myVideoV.setMediaController(new android.widget.MediaController(Main2Activity.this)); myVideoV.requestFocus(); myVideoV.start(); } }); Button btn2 = (Button)findViewById(R.id.button4); btn2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final VideoView myVideoV = (VideoView) findViewById(R.id.videoView1); myVideoV.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.f1)); myVideoV.setMediaController(new android.widget.MediaController(Main2Activity.this)); myVideoV.requestFocus(); myVideoV.start(); } });
final VideoView myVideoV = (VideoView)findViewById(R.id.videoView);
public class Main2Activity extends AppCompatActivity { ViewAnimator va; // MediaPlayer myVideoV; final VideoView myVideoV = (VideoView)findViewById(R.id.videoView); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); va = (ViewAnimator) findViewById(R.id.viewAnimator); final Animation in = AnimationUtils.loadAnimation(this, android.R.anim.fade_in); final Animation out = AnimationUtils.loadAnimation(this, android.R.anim.fade_in); final Button btn1 = (Button) findViewById(R.id.button2); btn1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { va.setInAnimation(in); va.showPrevious(); } }); Button btn2 = (Button) findViewById(R.id.button3); btn2.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { va.setInAnimation(out); va.showNext(); } }); button(); } //end onCreate public void button() { Button btn1 = (Button)findViewById(R.id.button); btn1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //final VideoView myVideoV = (VideoView)findViewById(R.id.videoView); myVideoV.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.a1)); myVideoV.setMediaController(new android.widget.MediaController(Main2Activity.this)); myVideoV.requestFocus(); myVideoV.start(); } }); Button btn2 = (Button)findViewById(R.id.button4); btn2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // final VideoView myVideoV = (VideoView) findViewById(R.id.videoView1); myVideoV.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.f1)); myVideoV.setMediaController(new android.widget.MediaController(Main2Activity.this)); myVideoV.requestFocus(); myVideoV.start(); } }); } }
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.nipon.app.testvdio.Main2Activity"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerHorizontal="true" android:layout_alignParentTop="true" android:weightSum="1"> <ViewAnimator android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/viewAnimator" android:layout_gravity="center_horizontal" android:layout_weight="0.94" > <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:weightSum="1"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal"> <VideoView android:layout_width="match_parent" android:layout_height="332dp" android:id="@+id/videoView" /> </LinearLayout> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Play" android:id="@+id/button" android:layout_gravity="center_horizontal" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="หน้า1" android:id="@+id/textView" android:textSize="30dp" android:layout_gravity="center_horizontal" /> </LinearLayout> //------------------------------- <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:weightSum="1"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal"> <VideoView android:layout_width="match_parent" android:layout_height="332dp" android:id="@+id/videoView1" /> </LinearLayout> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Play" android:id="@+id/button4" android:layout_gravity="center_horizontal" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="หน้า2" android:id="@+id/textView1" android:textSize="30dp" android:layout_gravity="center_horizontal" /> </LinearLayout> //------------------------------- </ViewAnimator> <LinearLayout android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="<<" android:id="@+id/button2" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=">>" android:id="@+id/button3" /> </LinearLayout> </LinearLayout> </RelativeLayout>
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง