我收到了一些视频的java.net.ProtocolException
。这是将URL传递到videoview
的方式。有人遇到过吗?
videoview.setVideoURI(videourl);
答案 0 :(得分:-1)
经过几轮调试,我发现这是由于不支持的视频格式。 Android默认的Mediaplayer或Videoview不支持所有格式,例如:MOV。
通过使用exoplayer,您可以解决此问题。 请选择支持的格式here。
private void initializePlayer(String downloadedFile) {
player = ExoPlayerFactory.newSimpleInstance(this);
player.addListener(eventListener);
DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "Player"));
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
MediaSource videoSource = new ExtractorMediaSource(streamurl,
dataSourceFactory, extractorsFactory, null, null);
player.prepare(videoSource, false, false);
player.setPlayWhenReady(true);
videoview.setShutterBackgroundColor(Color.TRANSPARENT);
videoview.setPlayer(player);
videoview.requestFocus();
}
@Override
public void onLoadingChanged(boolean isPlaying) {
Log.d(TAG,"videoplaying onLoadingChanged::"+isPlaying);
}
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
if (playbackState == ExoPlayer.STATE_BUFFERING){
//show progressbar
} else {
//dismiss progressbar
}
}
}