Tuesday, 10 September 2019

How to Create Video Music Player App in Android Studio | Video Media Player App in Android Studio



  
 
               In this post, we will see How to Create Video Music Player App in Android Studio or Video Media Player App in Android Studio. 



                How to create Android First App Hello World using Android Studio, check in following link:
https://www.comrevo.com/2019/09/Android-First-App-Hello-World-using-Android-Studio.html 
 
                To know how to install Android Studio in Linux, check following link:
https://www.comrevo.com/2019/01/how-to-install-android-studio-in-linux.html.

                To find details about Architecture of Android Operating System, check following link:
https://www.comrevo.com/2018/10/architecture-of-android-operating-system.html

Explanation:
                 We need to create raw folder (directory) in res folder. Copy and paste video file in this /res/raw folder. 

                   


Program (activity_main.xml) 

Design Mode:
                   Add widget VideoView to the Activity from widgets as shown in following screenshot. Set its attributes.



Text Mode:

 <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

Program (MainActivity.java)


package com.example.videoplayerapp;

import androidx.appcompat.app.AppCompatActivity;

import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends AppCompatActivity {

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

        VideoView videoView =(VideoView)findViewById(R.id.videoView);
        //Set MediaController  to enable play, pause, forward, etc options.
        MediaController mediaController= new MediaController(this);
        mediaController.setAnchorView(videoView);
        //Location of Media File
        Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.vaishnavjanato);
        //Starting VideView By Setting MediaController and URI
        videoView.setMediaController(mediaController);
        videoView.setVideoURI(uri);
        videoView.requestFocus();
        videoView.start();
    }
}

 
  
  
Output:  
                 Screenshot of the this app from mobile phone is as follows:  






No comments:

Post a comment