尝试在 exoplayer 中播放来自 arraylist 的视频时出现 IllegalSeekPositionException
IllegalSeekPositionException while trying to play video from arraylist in exoplayer
我正在尝试播放 exoplayer
中播放列表中的视频,但我最终收到此错误消息 com.google.android.exoplayer2.IllegalSeekPositionException
在下面,我将视频 Uri 列表添加到 exoplayer MediaItemBuilder
并使用 arraylist
播放视频,如 id player.seekTo(playListId, 0);
正在添加视频 Uri 并创建播放列表:
private void loadPlayList() {
File file = new File(String.valueOf(videoURI));
Log.d("TAG", "loadPlayList: " + file.getParent());
for (FileStore fs : db.getFilesByPath(file.getParent())) {
PlayListModel plm = new PlayListModel();
plm.setPlayListFilePath(fs.getFilePath());
playListArray.add(plm);
}
for (int i = 0; i < playListArray.size(); i++) {
if (playListArray.get(i).getPlayListFilePath().contains(videoURI.toString())) {
playListId = i;
Log.d("TAG", "loadPlayList Position: " + i);
}
}
}
private void initializePlayer() {
playerName.setText(videoName);
if (player == null) {
trackSelector = new DefaultTrackSelector(this);
RenderersFactory renderersFactory = new DefaultRenderersFactory(this)
.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON);
player = new SimpleExoPlayer.Builder(this, renderersFactory)
.setTrackSelector(trackSelector).build();
}
playerView.setPlayer(player);
mediaSession = new MediaSessionCompat(this, getString(R.string.app_name));
mediaSessionConnector = new MediaSessionConnector(mediaSession);
mediaSessionConnector.setPlayer(player);
playerView.setControllerShowTimeoutMs(CONTROLLER_TIMEOUT);
//playerView.setResizeMode(mPrefs.resizeMode);
for (int j = 0; j<playListArray.size(); j++) {
final String mimeType = Function.getMimeType(this, Uri.parse(playListArray.get(j).getPlayListFilePath()));
mediaItemBuilder = new MediaItem.Builder()
.setUri(playListArray.get(j).getPlayListFilePath())
.setMimeType(mimeType);
// Subtitle if statement.
if (subtitleUri != null && Function.fileExists(this, subtitleUri)) {
final String subtitleMime = Function.getSubtitleMime(subtitleUri);
final String subtitleLanguage = Function.getSubtitleLanguage(subtitleUri);
final String subtitleName = Function.getFileName(this, subtitleUri);
MediaItem.Subtitle subtitle = new MediaItem.Subtitle(subtitleUri, subtitleMime, subtitleLanguage, 0, C.ROLE_FLAG_SUBTITLE, subtitleName);
mediaItemBuilder.setSubtitles(Collections.singletonList(subtitle));
}
}
player.setMediaItem(mediaItemBuilder.build());
setTracks = true;
play = true;
player.setHandleAudioBecomingNoisy(true);
mediaSession.setActive(true);
player.addListener(playbackStateListener);
player.prepare();
player.seekTo(playListId, 0);
player.setPlayWhenReady(true);
}
What am i doing wrong while creating playlist in exoplayer.
终于可以从播放列表播放了,我没有准备播放列表,创建播放列表时出错,当我将有效的播放列表发送到 mediasource
时,我可以播放了
我正在尝试播放 exoplayer
中播放列表中的视频,但我最终收到此错误消息 com.google.android.exoplayer2.IllegalSeekPositionException
在下面,我将视频 Uri 列表添加到 exoplayer MediaItemBuilder
并使用 arraylist
播放视频,如 id player.seekTo(playListId, 0);
正在添加视频 Uri 并创建播放列表:
private void loadPlayList() {
File file = new File(String.valueOf(videoURI));
Log.d("TAG", "loadPlayList: " + file.getParent());
for (FileStore fs : db.getFilesByPath(file.getParent())) {
PlayListModel plm = new PlayListModel();
plm.setPlayListFilePath(fs.getFilePath());
playListArray.add(plm);
}
for (int i = 0; i < playListArray.size(); i++) {
if (playListArray.get(i).getPlayListFilePath().contains(videoURI.toString())) {
playListId = i;
Log.d("TAG", "loadPlayList Position: " + i);
}
}
}
private void initializePlayer() {
playerName.setText(videoName);
if (player == null) {
trackSelector = new DefaultTrackSelector(this);
RenderersFactory renderersFactory = new DefaultRenderersFactory(this)
.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON);
player = new SimpleExoPlayer.Builder(this, renderersFactory)
.setTrackSelector(trackSelector).build();
}
playerView.setPlayer(player);
mediaSession = new MediaSessionCompat(this, getString(R.string.app_name));
mediaSessionConnector = new MediaSessionConnector(mediaSession);
mediaSessionConnector.setPlayer(player);
playerView.setControllerShowTimeoutMs(CONTROLLER_TIMEOUT);
//playerView.setResizeMode(mPrefs.resizeMode);
for (int j = 0; j<playListArray.size(); j++) {
final String mimeType = Function.getMimeType(this, Uri.parse(playListArray.get(j).getPlayListFilePath()));
mediaItemBuilder = new MediaItem.Builder()
.setUri(playListArray.get(j).getPlayListFilePath())
.setMimeType(mimeType);
// Subtitle if statement.
if (subtitleUri != null && Function.fileExists(this, subtitleUri)) {
final String subtitleMime = Function.getSubtitleMime(subtitleUri);
final String subtitleLanguage = Function.getSubtitleLanguage(subtitleUri);
final String subtitleName = Function.getFileName(this, subtitleUri);
MediaItem.Subtitle subtitle = new MediaItem.Subtitle(subtitleUri, subtitleMime, subtitleLanguage, 0, C.ROLE_FLAG_SUBTITLE, subtitleName);
mediaItemBuilder.setSubtitles(Collections.singletonList(subtitle));
}
}
player.setMediaItem(mediaItemBuilder.build());
setTracks = true;
play = true;
player.setHandleAudioBecomingNoisy(true);
mediaSession.setActive(true);
player.addListener(playbackStateListener);
player.prepare();
player.seekTo(playListId, 0);
player.setPlayWhenReady(true);
}
What am i doing wrong while creating playlist in exoplayer.
终于可以从播放列表播放了,我没有准备播放列表,创建播放列表时出错,当我将有效的播放列表发送到 mediasource
时,我可以播放了