Wednesday 28 October 2015

VideoView example in Android

In this tutorial, you will learn how to stream a remote video by using a MediaController and display it into a VideoView in your Android Application. MediaController is a controller for Media Player such as functions like Play/Pause, Rewind, Fast Forward and a progress slider.
activity_main.xml
----------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
   
xmlns:android="http://schemas.android.com/apk/res/android"
   
xmlns:tools="http://schemas.android.com/tools"
   
xmlns:app="http://schemas.android.com/apk/res-auto"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent"
   
app:layout_behavior="@string/appbar_scrolling_view_behavior"
   
tools:showIn="@layout/activity_main"
   
tools:context=".MainActivity">


    <
VideoView
       
android:layout_width="wrap_content"
       
android:layout_height="match_parent"
       
android:id="@+id/videoView" />
</
LinearLayout>

MainActivity.Java
-----------------------------
package com.android.anil.videoplayer;

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

public class MainActivity extends AppCompatActivity {
VideoView
videoView;
   
@Override
   
protected void onCreate(Bundle savedInstanceState) {
        
super.onCreate(savedInstanceState);
        setContentView(R.layout.
activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.
toolbar);
        setSupportActionBar(toolbar);
       
videoView=(VideoView)findViewById(R.id.videoView);
        
videoView.setVideoURI(Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.sample1));
       
videoView.setMediaController(new MediaController(this));
       
videoView.start();
    }
}

Output is:
-----------------------------


No comments:

Post a Comment

Encryption Decryption Example Android Using AES Alogirthm

activity_main.xml ------------------------- <?xml version="1.0" encoding="utf-8"?> <LinearLayou...