我使用快视频库播放视频,但视频无法启动自动某人需要按播放按钮我需要自动播放视频,我在我的gradle中包含exoplayer
videoview.start();
不起作用......
这是我的片段代码
package com.Hristijan.Aleksandar.GymAssistant.Exercises;
import android.media.MediaPlayer;
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 com.warnyul.android.widget.FastVideoView;
public class BenchFragment extends Fragment {
private FastVideoView videoView;
public View rootView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_bench, container, false);
FastVideoView videoView = (FastVideoView)rootView.findViewById(R.id.videoplayer);
videoView.setMediaController(new MediaController(getActivity()));
videoView.setVideoPath("android.resource://" + getActivity().getPackageName() + "/" + R.raw.bench);
videoView.setMediaController(null);
videoView.start();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
mp.setVolume(0, 0);
}
});
return rootView;
}
}
答案 0 :(得分:2)
在MediaPlayer
方法中启动onPrepared()
,
试试这个,
videoView.setMediaController(new MediaController(getActivity()));
videoView.setVideoPath("android.resource://" + getActivity().getPackageName() + "/" + R.raw.bench);
videoView.setMediaController(null);
videoView.start();
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setLooping(true);
mp.setVolume(0, 0);
mp.start();
}
});