1

Hi guys I'm new to Android development I'm making Android app with Exercises so How can I Make Video to loop and Mute Audio using VideoView? I need Video to be Muted and to Loop just that nothing more

Thanks

Here is my code

BenchFragment.Java

package com.Hristijan.Aleksandar.GymAssistant.Exercises;

import android.net.Uri;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.MediaController;
import android.widget.VideoView;

public class BenchFragment extends Fragment {

    private VideoView player;
    private String videopath;
    private MediaController mediacon;
    public  View rootView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {

        rootView = inflater.inflate(R.layout.fragment_bench, container, false);
        mediacon = new MediaController(getActivity());
        player = (VideoView) rootView.findViewById(R.id.videoplayer);
        videopath = "android.resource://" + getActivity().getPackageName() + "/" + R.raw.bench;
        player.setVideoURI(Uri.parse(videopath));
        mediacon.setAnchorView(player);
        player.start();
        return rootView;
    }
}

fragment_bench.xml

<?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:id="@+id/bench_layout"
    android:layout_width="match_parent"
    android:background="#000000"
    android:layout_height="match_parent"
    tools:context="com.Hristijan.Aleksandar.GymAssistant.Exercises.BenchFragment">

        <VideoView
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:foregroundGravity="center"
            android:id="@+id/videoplayer" />

</RelativeLayout>
Komal12
  • 3,340
  • 4
  • 16
  • 25

1 Answers1

1

Call MediaPlayer.OnPreparedListener and MediaPlayer.OnCompletionListener, then you can call MediaPlayer.setVolume(0f, 0f);

videoview.setOnPreparedListener(new OnPreparedListener() {

    @Override
    public void onPrepared(MediaPlayer mp) {
        //.....do prepaid  
        mp.setVolume(0, 0);
        //Looping
        //m.setLooping(true);
        m.start();
    }
});

Or make it play again in

videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) {
            mp.start();
        }
    });
Thanh Le
  • 763
  • 4
  • 13