我正在开发一个 phonegap 应用程序,它有一个 VideoView 屏幕来播放音频(来自 Wowza 流引擎)。我的问题是,当 VideoView 在屏幕上加载时,我想立即播放音频。我的应用程序中当前正在发生的事情,当我的 VideoView 被加载时它甚至没有显示在屏幕上(当我触摸屏幕时它会显示,这是另一个问题)。
现在,当它出现在触摸屏上时,我必须单击播放按钮才能开始播放音频。(我正在使用 libstreaming 库)
这是我的代码-
activity_main.xml
<io.vov.vitamio.widget.VideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
android:visibility="visible"
/>
活动课:
private VideoView mVideoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
if (!LibsChecker.checkVitamioLibs(this))
return;
mVideoView = (VideoView) findViewById(R.id.video_view);
mVideoView.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);
mVideoView.getHolder().setFormat(PixelFormat.RGBX_8888);
startRtmpStream();
}
public void startRtmpStream() {
mVideoView.setVideoPath(AppConfig.STREAM_URL_AUDIO_ONLY);
mVideoView.setMediaController(new MediaController(this));
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
mediaPlayer.setPlaybackSpeed(1.0f);
}
});
mVideoView.start();
}
AppConfig.java
public class AppConfig {
public static final String STREAM_URL_AUDIO_ONLY = "rtmp://10.101.3.129:1935/app1/myStream";
public static final String PUBLISHER_USERNAME = "";
public static final String PUBLISHER_PASSWORD = "";}