Easy tutorial how to play your video from pc, offline, in Android Studio version 3.1.3, using MediaController widget. Create new project with Application name: My video; Minimum SDK: API 14Android 4 (IceCreamSandwich). In app->res->layout-> create New Directory: raw and copy-paste a video from your computer, with name: movie.mp4. In app->res->layout->activity_main.xml write the code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <VideoView
        android:id="@+id/videoView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

</android.support.constraint.ConstraintLayout>
  In app->java->MainActivity.java write the code:
package com.app.toyo.myvideo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.net.Uri;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends AppCompatActivity {

    VideoView myVideo;
    private MediaController media_control;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        myVideo = (VideoView) findViewById(R.id.videoView);
        Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.movie);
        media_control = new MediaController(this);
        myVideo.setMediaController(media_control);
        myVideo.setVideoURI(uri);
        myVideo.start();
    }
}
  Run app in mobile device or Emulator (API 27 Android 8.1) and watch your video in format portrait or landscape. Follow YouTube Video Tutorial:
  Download project with Source Code from here: https://android-coffee.com/wp-content/uploads/projecs/Myvideo.7z Please subscribe here to our YouTube channel. Thank you! Check next tutorials to learn all about Android. For further questions leave a message.  

Leave a Reply

Your email address will not be published. Required fields are marked *

Blue Captcha Image Refresh

*