Android Video Player VideoView, playing local and online videos, androidvideoview
1. layout File
<?xml version="1.0" encoding="utf-8"?><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="app.com.myapplication.LocalVideoActivity"> <RelativeLayout android:layout_width="match_parent" android:layout_height="200dp"> <VideoView android:id="@+id/videoView" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout></RelativeLayout>
2. Code
Package app.com. myapplication; import android. media. mediaPlayer; import android.net. uri; import android. OS. bundle; import android. OS. environment; import android. support. v7.app. appCompatActivity; import android. widget. mediaController; import android. widget. toast; import android. widget. videoView; public class LocalVideoActivity extends AppCompatActivity {private VideoView videoView; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_local_video); // Add a fl1234.mp4 video String videoUrl1 = Environment to the root directory of the mobile phone SD card. getExternalStorageDirectory (). getPath () + "/fl1234.mp4"; // network video String videoUrl2 = Utils. videoUrl; Uri uri = Uri. parse (videoUrl2); videoView = (VideoView) this. findViewById (R. id. videoView); // sets the Video Controller videoView. setMediaController (new MediaController (this); // call back videoView after playback is complete. setOnCompletionListener (new MyPlayerOnCompletionListener (); // sets the video path videoView. setVideoURI (uri); // start to play the video videoView. start ();} class MyPlayerOnCompletionListener implements MediaPlayer. onCompletionListener {@ Override public void onCompletion (MediaPlayer mp) {Toast. makeText (LocalVideoActivity. this, "the playback is complete", Toast. LENGTH_SHORT ). show ();}}}
package app.com.myapplication;/** * Created by ${zyj} on 2016/4/19. */public class Utils { public static final String videoUrl = "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" ;}
3. effect display