Play Video or Audio File from sdcard in android

Play Video or Audio File from sdcard in android - Hello friends U-See, In the article you read in this time with the title Play Video or Audio File from sdcard in android, We have prepared this article well for you to read and take the information in it. Hopefully the contents of the post Artikel Android, Which we write you can understand. Okay, happy reading.

Title: Play Video or Audio File from sdcard in android
link : Play Video or Audio File from sdcard in android

Read also


Play Video or Audio File from sdcard in android

In this Android Tutorial, we will learn how to play Video or Audio file from sdcard. First, Open your main XML file and drag VideoView and a button or paste below code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" >

    <VideoView
        android:id="@+id/videoView1"
        android:layout_width="300dp"
        android:layout_height="200dp"
      />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/videoView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:text="Play"
        android:onClick="play" />

</RelativeLayout>


Now open your Java file and paste below code:

package coders.hub.com; //your package name

importandroid.os.Bundle;
importandroid.view.View;
importandroid.widget.VideoView;
importandroid.app.Activity;

public class MainActivity extends Activity {
      VideoView v;

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

            v=(VideoView)findViewById(R.id.videoView1);

//give Video or audio path of sdcard here
            v.setVideoPath("/sdcard/Music/BigB.mp4");
      }
      public void play(View view)
      {
            v.start();
      }
 }


Now run your project...only video will display on VideoView if we are playing audio file than nothing will display but we can listen audio.


That's Play Video or Audio File from sdcard in android

That's an article Play Video or Audio File from sdcard in android This time, hopefully can benefit for you all. Well, see you in other article postings.

You are now reading the article Play Video or Audio File from sdcard in android With link address https://u-see1.blogspot.com/2017/06/play-video-or-audio-file-from-sdcard-in.html

Postingan terkait:

Belum ada tanggapan untuk "Play Video or Audio File from sdcard in android"

Post a Comment