Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #13904 - ExoPlayer can't start a new audio from a seek point #13905

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
* Android Service responsible for playback of voice notes.
Expand Down Expand Up @@ -171,8 +172,8 @@ public void onPositionDiscontinuity(@NonNull Player.PositionInfo oldPosition, @N
if (reason == Player.DISCONTINUITY_REASON_AUTO_TRANSITION) {
sendViewedReceiptForCurrentWindowIndex();
MediaItem currentMediaItem = player.getCurrentMediaItem();
if (currentMediaItem != null && currentMediaItem.playbackProperties != null) {
Log.d(TAG, "onPositionDiscontinuity: current window uri: " + currentMediaItem.playbackProperties.uri);
if (currentMediaItem != null && currentMediaItem.localConfiguration != null) {
Log.d(TAG, "onPositionDiscontinuity: current window uri: " + currentMediaItem.localConfiguration.uri);
}

PlaybackParameters playbackParameters = getPlaybackParametersForWindowPosition(mediaItemIndex);
Expand Down Expand Up @@ -221,12 +222,12 @@ private void onAttachmentDeleted() {
ContextCompat.getMainExecutor(getApplicationContext()).execute(() -> {
if (player != null) {
final MediaItem currentItem = player.getCurrentMediaItem();
if (currentItem == null || currentItem.playbackProperties == null) {
if (currentItem == null || currentItem.localConfiguration == null) {
Log.d(TAG, "Current item is null or playback properties are null.");
return;
}

final Uri currentlyPlayingUri = currentItem.playbackProperties.uri;
final Uri currentlyPlayingUri = currentItem.localConfiguration.uri;

if (currentlyPlayingUri == VoiceNoteMediaItemFactory.NEXT_URI || currentlyPlayingUri == VoiceNoteMediaItemFactory.END_URI) {
Log.v(TAG, "Attachment deleted while voice note service was playing a system tone.");
Expand Down Expand Up @@ -317,16 +318,16 @@ private boolean isAudioMessage(int currentWindowIndex) {
private void sendViewedReceiptForCurrentWindowIndex() {
if (player.getPlaybackState() == Player.STATE_READY &&
player.getPlayWhenReady() &&
player.getCurrentWindowIndex() != C.INDEX_UNSET)
player.getCurrentMediaItemIndex() != C.INDEX_UNSET)
{

MediaItem currentMediaItem = player.getCurrentMediaItem();
if (currentMediaItem == null || currentMediaItem.playbackProperties == null) {
if (currentMediaItem == null || currentMediaItem.localConfiguration == null) {
return;
}

Uri mediaUri = currentMediaItem.playbackProperties.uri;
if (!mediaUri.getScheme().equals("content")) {
Uri mediaUri = currentMediaItem.localConfiguration.uri;
if (!Objects.equals(mediaUri.getScheme(), "content")) {
return;
}

Expand All @@ -336,7 +337,7 @@ private void sendViewedReceiptForCurrentWindowIndex() {
return;
}
long messageId = extras.getLong(VoiceNoteMediaItemFactory.EXTRA_MESSAGE_ID);
RecipientId recipientId = RecipientId.from(extras.getString(VoiceNoteMediaItemFactory.EXTRA_INDIVIDUAL_RECIPIENT_ID));
RecipientId recipientId = RecipientId.from(Objects.requireNonNull(extras.getString(VoiceNoteMediaItemFactory.EXTRA_INDIVIDUAL_RECIPIENT_ID)));
MessageTable messageDatabase = SignalDatabase.messages();

MessageTable.MarkedMessageInfo markedMessageInfo = messageDatabase.setIncomingMessageViewed(messageId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class VoiceNotePlayer @JvmOverloads constructor(
val isSeekingToStart = positionMs == C.TIME_UNSET

return if (isQueueToneIndex && isSeekingToStart) {
val nextVoiceNoteWindowIndex = if (currentWindowIndex < windowIndex) windowIndex + 1 else windowIndex - 1
val nextVoiceNoteWindowIndex = if (currentMediaItemIndex < windowIndex) windowIndex + 1 else windowIndex - 1
if (mediaItemCount <= nextVoiceNoteWindowIndex) {
super.seekTo(windowIndex, positionMs)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ class VoiceNotePlayerCallback(val context: Context, val player: VoiceNotePlayer)
}
}
})
player.addListener(
object : Player.Listener {
override fun onPlaybackStateChanged(playbackState: Int) {
super.onPlaybackStateChanged(playbackState)
if(playbackState == Player.STATE_READY) {
player.seekTo(window, (player.duration * progress).toLong())
player.removeListener(this)
}
}
}
)
player.prepare()
canLoadMore = !singlePlayback
} else if (latestUri == uri) {
Expand Down Expand Up @@ -217,7 +228,7 @@ class VoiceNotePlayerCallback(val context: Context, val player: VoiceNotePlayer)

private fun indexOfPlayerMediaItemByUri(uri: Uri): Int {
for (i in 0 until player.mediaItemCount) {
val playbackProperties: LocalConfiguration? = player.getMediaItemAt(i).playbackProperties
val playbackProperties: LocalConfiguration? = player.getMediaItemAt(i).localConfiguration
if (playbackProperties?.uri == uri) {
return i
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import androidx.media3.common.MediaItem;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.datasource.DataSource;
import androidx.media3.datasource.DataSpec;
import androidx.media3.datasource.TransferListener;
import androidx.media3.exoplayer.drm.DrmSessionManagerProvider;
import androidx.media3.exoplayer.source.MediaSource;
import androidx.media3.exoplayer.source.ProgressiveMediaSource;
Expand Down