Add:Android setting to use mp3 index seeking #638

This commit is contained in:
advplyr 2023-06-17 11:27:44 -05:00
parent 4f03c2a35d
commit 9e7d1d1617
4 changed files with 52 additions and 5 deletions

View file

@ -109,6 +109,7 @@ data class DeviceSettings(
var enableAltView:Boolean, var enableAltView:Boolean,
var jumpBackwardsTime:Int, var jumpBackwardsTime:Int,
var jumpForwardTime:Int, var jumpForwardTime:Int,
var enableMp3IndexSeeking:Boolean,
var disableShakeToResetSleepTimer:Boolean, var disableShakeToResetSleepTimer:Boolean,
var shakeSensitivity: ShakeSensitivitySetting, var shakeSensitivity: ShakeSensitivitySetting,
var lockOrientation: LockOrientationSetting, var lockOrientation: LockOrientationSetting,
@ -130,6 +131,7 @@ data class DeviceSettings(
enableAltView = true, enableAltView = true,
jumpBackwardsTime = 10, jumpBackwardsTime = 10,
jumpForwardTime = 10, jumpForwardTime = 10,
enableMp3IndexSeeking = false,
disableShakeToResetSleepTimer = false, disableShakeToResetSleepTimer = false,
shakeSensitivity = ShakeSensitivitySetting.MEDIUM, shakeSensitivity = ShakeSensitivitySetting.MEDIUM,
lockOrientation = LockOrientationSetting.NONE, lockOrientation = LockOrientationSetting.NONE,

View file

@ -43,6 +43,8 @@ import com.google.android.exoplayer2.audio.AudioAttributes
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector.CustomActionProvider import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector.CustomActionProvider
import com.google.android.exoplayer2.ext.mediasession.TimelineQueueNavigator import com.google.android.exoplayer2.ext.mediasession.TimelineQueueNavigator
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory
import com.google.android.exoplayer2.extractor.mp3.Mp3Extractor
import com.google.android.exoplayer2.source.MediaSource import com.google.android.exoplayer2.source.MediaSource
import com.google.android.exoplayer2.source.ProgressiveMediaSource import com.google.android.exoplayer2.source.ProgressiveMediaSource
import com.google.android.exoplayer2.source.hls.HlsMediaSource import com.google.android.exoplayer2.source.hls.HlsMediaSource
@ -437,12 +439,26 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
if (playbackSession.isLocal) { if (playbackSession.isLocal) {
Log.d(tag, "Playing Local Item") Log.d(tag, "Playing Local Item")
val dataSourceFactory = DefaultDataSource.Factory(ctx) val dataSourceFactory = DefaultDataSource.Factory(ctx)
mediaSource = ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mediaItems[0])
val extractorsFactory = DefaultExtractorsFactory()
if (DeviceManager.deviceData.deviceSettings?.enableMp3IndexSeeking == true) {
// @see https://exoplayer.dev/troubleshooting.html#why-is-seeking-inaccurate-in-some-mp3-files
extractorsFactory.setMp3ExtractorFlags(Mp3Extractor.FLAG_ENABLE_INDEX_SEEKING)
}
mediaSource = ProgressiveMediaSource.Factory(dataSourceFactory, extractorsFactory).createMediaSource(mediaItems[0])
} else if (!playbackSession.isHLS) { } else if (!playbackSession.isHLS) {
Log.d(tag, "Direct Playing Item") Log.d(tag, "Direct Playing Item")
val dataSourceFactory = DefaultHttpDataSource.Factory() val dataSourceFactory = DefaultHttpDataSource.Factory()
val extractorsFactory = DefaultExtractorsFactory()
if (DeviceManager.deviceData.deviceSettings?.enableMp3IndexSeeking == true) {
// @see https://exoplayer.dev/troubleshooting.html#why-is-seeking-inaccurate-in-some-mp3-files
extractorsFactory.setMp3ExtractorFlags(Mp3Extractor.FLAG_ENABLE_INDEX_SEEKING)
}
dataSourceFactory.setUserAgent(channelId) dataSourceFactory.setUserAgent(channelId)
mediaSource = ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mediaItems[0]) mediaSource = ProgressiveMediaSource.Factory(dataSourceFactory, extractorsFactory).createMediaSource(mediaItems[0])
} else { } else {
Log.d(tag, "Playing HLS Item") Log.d(tag, "Playing HLS Item")
val dataSourceFactory = DefaultHttpDataSource.Factory() val dataSourceFactory = DefaultHttpDataSource.Factory()

View file

@ -7,6 +7,7 @@
"build": "nuxt build", "build": "nuxt build",
"start": "nuxt start", "start": "nuxt start",
"generate": "nuxt generate", "generate": "nuxt generate",
"sync": "nuxt generate && npx cap sync",
"icons-android": "cordova-res android --skip-config --copy", "icons-android": "cordova-res android --skip-config --copy",
"ionic:build": "npm run build", "ionic:build": "npm run build",
"ionic:serve": "npm run start" "ionic:serve": "npm run start"
@ -43,4 +44,4 @@
"postcss": "^8.3.5", "postcss": "^8.3.5",
"tailwindcss": "^3.3.2" "tailwindcss": "^3.3.2"
} }
} }

View file

@ -22,7 +22,7 @@
</div> </div>
<!-- Playback settings --> <!-- Playback settings -->
<p class="uppercase text-xs font-semibold text-gray-300 mb-2 mt-6">Playback Settings</p> <p class="uppercase text-xs font-semibold text-gray-300 mb-2 mt-10">Playback Settings</p>
<div v-if="!isiOS" class="flex items-center py-3" @click="toggleDisableAutoRewind"> <div v-if="!isiOS" class="flex items-center py-3" @click="toggleDisableAutoRewind">
<div class="w-10 flex justify-center"> <div class="w-10 flex justify-center">
<ui-toggle-switch v-model="settings.disableAutoRewind" @input="saveSettings" /> <ui-toggle-switch v-model="settings.disableAutoRewind" @input="saveSettings" />
@ -41,10 +41,17 @@
</div> </div>
<p class="pl-4">Jump forwards time</p> <p class="pl-4">Jump forwards time</p>
</div> </div>
<div v-if="!isiOS" class="flex items-center py-3" @click="toggleEnableMp3IndexSeeking">
<div class="w-10 flex justify-center">
<ui-toggle-switch v-model="settings.enableMp3IndexSeeking" @input="saveSettings" />
</div>
<p class="pl-4">Enable mp3 index seeking</p>
<span class="material-icons-outlined ml-2" @click.stop="showConfirmMp3IndexSeeking">info</span>
</div>
<!-- Sleep timer settings --> <!-- Sleep timer settings -->
<template v-if="!isiOS"> <template v-if="!isiOS">
<p class="uppercase text-xs font-semibold text-gray-300 mb-2 mt-6">Sleep Timer Settings</p> <p class="uppercase text-xs font-semibold text-gray-300 mb-2 mt-10">Sleep Timer Settings</p>
<div class="flex items-center py-3" @click="toggleDisableShakeToResetSleepTimer"> <div class="flex items-center py-3" @click="toggleDisableShakeToResetSleepTimer">
<div class="w-10 flex justify-center"> <div class="w-10 flex justify-center">
<ui-toggle-switch v-model="settings.disableShakeToResetSleepTimer" @input="saveSettings" /> <ui-toggle-switch v-model="settings.disableShakeToResetSleepTimer" @input="saveSettings" />
@ -131,6 +138,7 @@ export default {
enableAltView: false, enableAltView: false,
jumpForwardTime: 10, jumpForwardTime: 10,
jumpBackwardsTime: 10, jumpBackwardsTime: 10,
enableMp3IndexSeeking: false,
disableShakeToResetSleepTimer: false, disableShakeToResetSleepTimer: false,
shakeSensitivity: 'MEDIUM', shakeSensitivity: 'MEDIUM',
lockOrientation: 0, lockOrientation: 0,
@ -165,6 +173,10 @@ export default {
autoSleepTimerAutoRewind: { autoSleepTimerAutoRewind: {
name: 'Enable sleep timer auto rewind', name: 'Enable sleep timer auto rewind',
message: 'When the auto sleep timer finishes, playing the item again will automatically rewind your position.' message: 'When the auto sleep timer finishes, playing the item again will automatically rewind your position.'
},
enableMp3IndexSeeking: {
name: 'Enable mp3 index seeking',
message: 'This setting should only be enabled if you have mp3 files that are not seeking correctly. Inaccurate seeking is most likely due to Variable birate (VBR) MP3 files. This setting will force index seeking, in which a time-to-byte mapping is built as the file is read. In some cases with large MP3 files there will be a delay when seeking towards the end of the file.'
} }
}, },
hapticFeedbackItems: [ hapticFeedbackItems: [
@ -315,6 +327,20 @@ export default {
}) })
} }
}, },
async showConfirmMp3IndexSeeking() {
const confirmResult = await Dialog.confirm({
title: this.settingInfo.enableMp3IndexSeeking.name,
message: this.settingInfo.enableMp3IndexSeeking.message,
cancelButtonTitle: 'View More'
})
if (!confirmResult.value) {
window.open('https://exoplayer.dev/troubleshooting.html#why-is-seeking-inaccurate-in-some-mp3-files', '_blank')
}
},
toggleEnableMp3IndexSeeking() {
this.settings.enableMp3IndexSeeking = !this.settings.enableMp3IndexSeeking
this.saveSettings()
},
toggleAutoSleepTimer() { toggleAutoSleepTimer() {
this.settings.autoSleepTimer = !this.settings.autoSleepTimer this.settings.autoSleepTimer = !this.settings.autoSleepTimer
this.saveSettings() this.saveSettings()
@ -388,6 +414,8 @@ export default {
this.settings.enableAltView = !!deviceSettings.enableAltView this.settings.enableAltView = !!deviceSettings.enableAltView
this.settings.jumpForwardTime = deviceSettings.jumpForwardTime || 10 this.settings.jumpForwardTime = deviceSettings.jumpForwardTime || 10
this.settings.jumpBackwardsTime = deviceSettings.jumpBackwardsTime || 10 this.settings.jumpBackwardsTime = deviceSettings.jumpBackwardsTime || 10
this.settings.toggleEnableMp3IndexSeeking = !!deviceSettings.toggleEnableMp3IndexSeeking
this.settings.lockOrientation = deviceSettings.lockOrientation || 'NONE' this.settings.lockOrientation = deviceSettings.lockOrientation || 'NONE'
this.lockCurrentOrientation = this.settings.lockOrientation !== 'NONE' this.lockCurrentOrientation = this.settings.lockOrientation !== 'NONE'
this.settings.hapticFeedback = deviceSettings.hapticFeedback || 'LIGHT' this.settings.hapticFeedback = deviceSettings.hapticFeedback || 'LIGHT'