Android Video player Videoview use, play local video and network video

Source: Internet
Author: User

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 part
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 classLocalvideoactivity extends Appcompatactivity {PrivateVideoview Videoview; @Overrideprotected voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_local_video); //Local video needs to add a fl1234.mp4 video to the phone's SD card root directoryString VIDEOURL1 = Environment.getexternalstoragedirectory (). GetPath () +"/fl1234.mp4" ; //Network VideoString VIDEOURL2 =Utils.videourl; Uri URI=Uri.parse (VIDEOURL2); Videoview= (Videoview) This. Findviewbyid (R.id.videoview); //setting up a video controllerVideoview.setmediacontroller (NewMediacontroller ( This)); //Play Completion callbackVideoview.setoncompletionlistener (NewMyplayeroncompletionlistener ()); //set the video pathVideoview.setvideouri (URI); //start playing videoVideoview.start (); }    classMyplayeroncompletionlistener implements Mediaplayer.oncompletionlistener {@Override Public voidOncompletion (MediaPlayer MP) {Toast.maketext (localvideoactivity. This,"playback is complete.", Toast.length_short). Show (); }    }}

Package app.com.myapplication; /*  */Publicclass  Utils    {publicstatic " Http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4 "  ;}

3. Effect display

Android Video player Videoview use, play local video and network video

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.