Android Video Player VideoView, playing local and online videos, androidvideoview

Source: Internet
Author: User
Tags call back

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

 

 

 

 

 

 

 

Related Article

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.