如何使视频循环和静音音频VideoView

时间:2018-02-24 16:57:55

标签: android

大家好我是Android开发新手我正在用练习制作Android应用程序 那么如何使用VideoView使视频循环和静音? 我需要将视频静音,然后再循环播放

由于

这是我的代码

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>

0 个答案:

没有答案