1, the effect shows
2. 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>
3, Code section
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); Local video needs to add a fl1234.mp4 video String videoUrl1 = Environment.getexternalstoragedirectory () to the phone's SD card root directory. GetPath () + "/fl1234
. mp4 ";
Network video String videoUrl2 = Utils.videourl;
Uri uri = Uri.parse (VIDEOURL2);
Videoview = (videoview) This.findviewbyid (R.id.videoview);
Set the video controller Videoview.setmediacontroller (new Mediacontroller (this)); Playback Complete callback Videoview.setoncompletionlistener (new MyplayeroncompletionlisteneR ());
Sets the video path Videoview.setvideouri (URI);
Start playing video Videoview.start (); Class Myplayeroncompletionlistener implements Mediaplayer.oncompletionlistener {@Override public void oncom
Pletion (MediaPlayer MP) {Toast.maketext (Localvideoactivity.this, "Play completed", 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 ";
}
4, summary
Android's way of using Videoview to play local video and web video is almost over, and hopefully it will help to develop Android. If you have questions, you can leave a message for discussion.