直播源码APP,基于googleExoPlayer简单⾃定义播放界⾯直播源码APP,基于google ExoPlayer 简单⾃定义播放界⾯实现的相关代码
1.直播源码AP基于google ExoPlayer播放m3u8,mp4等⽂件
简单⾃定义播放界⾯,新建⼀个Layout
布局⽂件命名为exo_playback_control_view,控件的id不能随便起,
要与exoPlayer原来PlaybackControlView的布局控件id,名称⼀致,
布局名称不⼀定是exo_playback_control_view,不过需要在SimpleExoPlayerView控件中添加⼀个:
app:controller_layout_id="@layout/id",指定control的布局;如:
2.如果需要详细的⾃定义播放界⾯,需要直播源码AP重写SimpleExoPlayerView,和PlaybackControlView。
3.重要的类
/**
* 监听播放状态
*/
private final class ComponentListener implements ExoPlayer.EventListener {
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
switch (playbackState) {
/**
* The player is able to immediately
/*play from its current position. The player will be playing if
* {@link #getPlayWhenReady()} is true, and paused otherwise.
*/
case Player.STATE_READY://
showLoading(false);
play(playWhenReady);
break;
/**
* The player has finished playing the media.
*/
case Player.STATE_ENDED:
showLoading(false);
playDefault();
break;
/
**
* The player does not have any media to play.
*/
case Player.STATE_IDLE:
showLoading(true);
break;
/**安卓课程设计源代码
* The player is not able to
/*immediately play from its current position. This state typically
* occurs when more data needs to be loaded.
*/
case Player.STATE_BUFFERING:
showLoading(true);
break;
}
}
@Override
public void onRepeatModeChanged(int repeatMode) {
// Do nothing.
}
@Override
public void onPositionDiscontinuity() {
/
/ Do nothing.
}
@Override
public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
// Do nothing.
}
@Override
public void onTimelineChanged(Timeline timeline, Object manifest) {
// Do nothing.
}
@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
// Do nothing.
}
@Override
public void onLoadingChanged(boolean isLoading) {
// Do nothing.
}
@Override
public void onPlayerError(ExoPlaybackException error) {
// Do nothing.
}
}
4.重要的⽅法:
/**
* 根据不同的Uri⽂件,⽣成不同的MediaSource
*
* @param uri
* @param overrideExtension
* @return
*/
private MediaSource buildMediaSource(Uri uri, String overrideExtension) {
int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ?
"." + overrideExtension
: LastPathSegment());
switch (type) {
case C.TYPE_SS:
return new SsMediaSource(uri, buildDataSourceFactory(false),
new DefaultSsChunkSource.Factory(mediaDataSourceFactory), null, null);
case C.TYPE_DASH:
return new DashMediaSource(uri, buildDataSourceFactory(false),
new DefaultDashChunkSource.Factory(mediaDataSourceFactory), null, null);
case C.TYPE_HLS:
return new HlsMediaSource(uri, mediaDataSourceFactory, null, null);
case C.TYPE_OTHER:
return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(),
null, null);
default: {
throw new IllegalStateException("Unsupported type: " + type);
}
}
}
以上就是直播源码APP,基于google ExoPlayer 简单⾃定义播放界⾯实现的相关代码,更多内容欢迎关注之后的⽂章

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。