mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 13:08:46 +00:00
Add support for audio to start from a seek position.
This commit is contained in:
@@ -49,6 +49,7 @@ import org.thoughtcrime.securesms.service.KeyCachingService;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Android Service responsible for playback of voice notes.
|
||||
@@ -171,8 +172,8 @@ public class VoiceNotePlaybackService extends MediaSessionService {
|
||||
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);
|
||||
@@ -221,12 +222,12 @@ public class VoiceNotePlaybackService extends MediaSessionService {
|
||||
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.");
|
||||
@@ -317,16 +318,16 @@ public class VoiceNotePlaybackService extends MediaSessionService {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -336,7 +337,7 @@ public class VoiceNotePlaybackService extends MediaSessionService {
|
||||
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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -155,6 +155,16 @@ class VoiceNotePlayerCallback(val context: Context, val player: VoiceNotePlayer)
|
||||
}
|
||||
}
|
||||
})
|
||||
player.addListener(
|
||||
object : Player.Listener {
|
||||
override fun onPlaybackStateChanged(playbackState: Int) {
|
||||
if (playbackState == Player.STATE_READY) {
|
||||
player.seekTo(window, (player.duration * progress).toLong())
|
||||
player.removeListener(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
player.prepare()
|
||||
canLoadMore = !singlePlayback
|
||||
} else if (latestUri == uri) {
|
||||
@@ -217,7 +227,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
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ import androidx.media3.common.C;
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user