Skip to content

Commit

Permalink
6.5.4 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
XilinJia committed Sep 4, 2024
1 parent 943ead2 commit 782c582
Show file tree
Hide file tree
Showing 51 changed files with 1,338 additions and 1,458 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ android {
testApplicationId "ac.mdiq.podcini.tests"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

versionCode 3020237
versionName "6.5.3"
versionCode 3020238
versionName "6.5.4"

applicationId "ac.mdiq.podcini.R"
def commit = ""
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
</activity>

<activity
android:name=".ui.activity.OnlineFeedViewActivity"
android:name=".ui.activity.ShareReceiverActivity"
android:configChanges="orientation|screenSize"
android:theme="@style/Theme.Podcini.Dark.Translucent"
android:label="@string/add_feed_label"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ class FeedHandler {
state.namespaces[uri] = Itunes()
Logd(TAG, "Recognized ITunes namespace")
}
uri == YouTube.NSURI && prefix == YouTube.NSTAG -> {
state.namespaces[uri] = YouTube()
Logd(TAG, "Recognized YouTube namespace")
}
// uri == YouTube.NSURI && prefix == YouTube.NSTAG -> {
// state.namespaces[uri] = YouTube()
// Logd(TAG, "Recognized YouTube namespace")
// }
uri == SimpleChapters.NSURI && prefix.matches(SimpleChapters.NSTAG.toRegex()) -> {
state.namespaces[uri] = SimpleChapters()
Logd(TAG, "Recognized SimpleChapters namespace")
Expand All @@ -238,6 +238,7 @@ class FeedHandler {
state.namespaces[uri] = PodcastIndex()
Logd(TAG, "Recognized PodcastIndex namespace")
}
else -> Logd(TAG, "startPrefixMapping can not handle uri: $uri")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ac.mdiq.podcini.net.feed.parser.element.SyndElement
import ac.mdiq.podcini.net.feed.parser.utils.DurationParser.inMillis
import org.xml.sax.Attributes

// TODO: this appears not needed
class YouTube : Namespace() {
val TAG = this::class.simpleName ?: "Anonymous"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ abstract class ServiceStatusHandler(private val activity: FragmentActivity) {
try {
activity.unregisterReceiver(statusUpdate)
activity.unregisterReceiver(notificationReceiver)
} catch (e: IllegalArgumentException) {
// ignore
}
} catch (e: IllegalArgumentException) {/* ignore */ }
initialized = false
cancelFlowEvents()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class LocalMediaPlayer(context: Context, callback: MediaPlayerCallback) : MediaP

@Throws(IllegalArgumentException::class, IllegalStateException::class)
private fun setDataSource(metadata: MediaMetadata, media: EpisodeMedia) {
Logd(TAG, "setDataSource1 called")
val url = media.getStreamUrl() ?: return
val preferences = media.episodeOrFetch()?.feed?.preferences
val user = preferences?.username
Expand All @@ -191,7 +192,7 @@ class LocalMediaPlayer(context: Context, callback: MediaPlayerCallback) : MediaP
val vService = Vista.getService(0)
val streamInfo = StreamInfo.getInfo(vService, url)
val audioStreamsList = getFilteredAudioStreams(streamInfo.audioStreams)
Logd(TAG, "setDataSource1 got ${audioStreamsList.size}")
Logd(TAG, "setDataSource1 audioStreamsList ${audioStreamsList.size}")
val audioIndex = if (isNetworkRestricted) 0 else audioStreamsList.size - 1
val audioStream = audioStreamsList[audioIndex]
Logd(TAG, "setDataSource1 use audio quality: ${audioStream.bitrate}")
Expand Down Expand Up @@ -346,31 +347,37 @@ class LocalMediaPlayer(context: Context, callback: MediaPlayerCallback) : MediaP
callback.ensureMediaInfoLoaded(curMedia!!)
callback.onMediaChanged(false)
setPlaybackParams(getCurrentPlaybackSpeed(curMedia), UserPreferences.isSkipSilence)
when {
streaming -> {
val streamurl = curMedia!!.getStreamUrl()
if (streamurl != null) {
val media = curMedia
if (media is EpisodeMedia) {
val deferred = CoroutineScope(Dispatchers.IO).async { setDataSource(metadata, media) }
if (startWhenPrepared) runBlocking { deferred.await() }
CoroutineScope(Dispatchers.IO).launch {
when {
streaming -> {
val streamurl = curMedia!!.getStreamUrl()
if (streamurl != null) {
val media = curMedia
if (media is EpisodeMedia) {
mediaItem = null
mediaSource = null
setDataSource(metadata, media)
// val deferred = CoroutineScope(Dispatchers.IO).async { setDataSource(metadata, media) }
// if (startWhenPrepared) runBlocking { deferred.await() }
// val preferences = media.episodeOrFetch()?.feed?.preferences
// setDataSource(metadata, streamurl, preferences?.username, preferences?.password)
} else setDataSource(metadata, streamurl, null, null)
} else setDataSource(metadata, streamurl, null, null)
}
}
}
else -> {
val localMediaurl = curMedia!!.getLocalMediaUrl()
else -> {
val localMediaurl = curMedia!!.getLocalMediaUrl()
// File(localMediaurl).canRead() time consuming, leave it to MediaItem to handle
// if (!localMediaurl.isNullOrEmpty() && File(localMediaurl).canRead()) setDataSource(metadata, localMediaurl, null, null)
if (!localMediaurl.isNullOrEmpty()) setDataSource(metadata, localMediaurl, null, null)
else throw IOException("Unable to read local file $localMediaurl")
if (!localMediaurl.isNullOrEmpty()) setDataSource(metadata, localMediaurl, null, null)
else throw IOException("Unable to read local file $localMediaurl")
}
}
withContext(Dispatchers.Main) {
val uiModeManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager
if (uiModeManager.currentModeType != Configuration.UI_MODE_TYPE_CAR) setPlayerStatus(PlayerStatus.INITIALIZED, curMedia)
if (prepareImmediately) prepare()
}
}
val uiModeManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager
if (uiModeManager.currentModeType != Configuration.UI_MODE_TYPE_CAR) setPlayerStatus(PlayerStatus.INITIALIZED, curMedia)

if (prepareImmediately) prepare()
} catch (e: IOException) {
e.printStackTrace()
setPlayerStatus(PlayerStatus.ERROR, null)
Expand All @@ -394,6 +401,7 @@ class LocalMediaPlayer(context: Context, callback: MediaPlayerCallback) : MediaP
seekTo(newPosition)
}
if (exoPlayer?.playbackState == STATE_IDLE || exoPlayer?.playbackState == STATE_ENDED ) prepareWR()
// while (mediaItem == null && mediaSource == null) runBlocking { delay(100) }
exoPlayer?.play()
// Can't set params when paused - so always set it on start in case they changed
exoPlayer?.playbackParameters = playbackParameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ import kotlin.math.max
*/
@UnstableApi
class PlaybackService : MediaLibraryService() {

private var mediaSession: MediaLibrarySession? = null

internal var mPlayer: MediaPlayerBase? = null
Expand Down Expand Up @@ -230,6 +229,37 @@ class PlaybackService : MediaLibraryService() {
}
}

private val shutdownReceiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Log.d(TAG, "shutdownReceiver onReceive called with action: ${intent.action}")
if (intent.action == ACTION_SHUTDOWN_PLAYBACK_SERVICE)
EventFlow.postEvent(FlowEvent.PlaybackServiceEvent(FlowEvent.PlaybackServiceEvent.Action.SERVICE_SHUT_DOWN))
}
}

val rootItem = MediaItem.Builder()
.setMediaId("CurQueue")
.setMediaMetadata(
MediaMetadata.Builder()
.setIsBrowsable(true)
.setIsPlayable(false)
.setMediaType(MediaMetadata.MEDIA_TYPE_FOLDER_MIXED)
.setTitle(curQueue.name)
.build())
.build()

val mediaItemsInQueue: MutableList<MediaItem> by lazy {
val list = mutableListOf<MediaItem>()
curQueue.episodes.forEach {
if (it.media != null) {
val item = buildMediaItem(it.media!!)
if (item != null) list += item
}
}
Logd(TAG, "mediaItemsInQueue: ${list.size}")
list
}

private val mediaPlayerCallback: MediaPlayerCallback = object : MediaPlayerCallback {
override fun statusChanged(newInfo: MediaPlayerInfo?) {
currentMediaType = mPlayer?.mediaType ?: MediaType.UNKNOWN
Expand Down Expand Up @@ -391,21 +421,18 @@ class PlaybackService : MediaLibraryService() {
j = if (curIndexInQueue >= 0 && curIndexInQueue < eList.size) curIndexInQueue else eList.size-1
} else if (i < eList.size-1) j = i+1
Logd(TAG, "getNextInQueue next j: $j")

val nextItem = unmanaged(eList[j])
Logd(TAG, "getNextInQueue nextItem ${nextItem.title}")
if (nextItem.media == null) {
Logd(TAG, "getNextInQueue nextItem: $nextItem media is null")
writeNoMediaPlaying()
return null
}

if (!isFollowQueue) {
Logd(TAG, "getNextInQueue(), but follow queue is not enabled.")
writeMediaPlaying(nextItem.media, PlayerStatus.STOPPED)
return null
}

if (!nextItem.media!!.localFileAvailable() && !isStreamingAllowed && isFollowQueue && nextItem.feed?.isLocalFeed != true) {
Logd(TAG, "getNextInQueue nextItem has no local file ${nextItem.title}")
displayStreamingNotAllowedNotification(PlaybackServiceStarter(this@PlaybackService, nextItem.media!!).intent)
Expand Down Expand Up @@ -433,11 +460,9 @@ class PlaybackService : MediaLibraryService() {
else -> EXTRA_CODE_AUDIO
})
}

override fun ensureMediaInfoLoaded(media: Playable) {
// if (media is EpisodeMedia && media.item == null) media.item = DBReader.getFeedItem(media.itemId)
}

fun writeMediaPlaying(playable: Playable?, playerStatus: PlayerStatus) {
Logd(InTheatre.TAG, "Writing playback preferences ${playable?.getIdentifier()}")
if (playable == null) writeNoMediaPlaying()
Expand All @@ -457,14 +482,12 @@ class PlaybackService : MediaLibraryService() {
}
}
}

fun writePlayerStatus(playerStatus: PlayerStatus) {
Logd(InTheatre.TAG, "Writing player status playback preferences")
curState = upsertBlk(curState) {
it.curPlayerStatus = getCurPlayerStatusAsInt(playerStatus)
}
}

private fun getCurPlayerStatusAsInt(playerStatus: PlayerStatus): Int {
val playerStatusAsInt = when (playerStatus) {
PlayerStatus.PLAYING -> PLAYER_STATUS_PLAYING
Expand All @@ -475,37 +498,6 @@ class PlaybackService : MediaLibraryService() {
}
}

private val shutdownReceiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Log.d(TAG, "shutdownReceiver onReceive called with action: ${intent.action}")
if (intent.action == ACTION_SHUTDOWN_PLAYBACK_SERVICE)
EventFlow.postEvent(FlowEvent.PlaybackServiceEvent(FlowEvent.PlaybackServiceEvent.Action.SERVICE_SHUT_DOWN))
}
}

val rootItem = MediaItem.Builder()
.setMediaId("CurQueue")
.setMediaMetadata(
MediaMetadata.Builder()
.setIsBrowsable(true)
.setIsPlayable(false)
.setMediaType(MediaMetadata.MEDIA_TYPE_FOLDER_MIXED)
.setTitle(curQueue.name)
.build())
.build()

val mediaItemsInQueue: MutableList<MediaItem> by lazy {
val list = mutableListOf<MediaItem>()
curQueue.episodes.forEach {
if (it.media != null) {
val item = buildMediaItem(it.media!!)
if (item != null) list += item
}
}
Logd(TAG, "mediaItemsInQueue: ${list.size}")
list
}

private val mediaLibrarySessionCK = object: MediaLibrarySession.Callback {
override fun onConnect(session: MediaSession, controller: MediaSession.ControllerInfo): MediaSession.ConnectionResult {
Logd(TAG, "in MyMediaSessionCallback onConnect")
Expand Down Expand Up @@ -762,9 +754,9 @@ class PlaybackService : MediaLibraryService() {
val keycode = intent?.getIntExtra(MediaButtonReceiver.EXTRA_KEYCODE, -1) ?: -1
val customAction = intent?.getStringExtra(MediaButtonReceiver.EXTRA_CUSTOM_ACTION)
val hardwareButton = intent?.getBooleanExtra(MediaButtonReceiver.EXTRA_HARDWAREBUTTON, false) ?: false
val keyEvent: KeyEvent? = if (Build.VERSION.SDK_INT >= VERSION_CODES.TIRAMISU) {
val keyEvent: KeyEvent? = if (Build.VERSION.SDK_INT >= VERSION_CODES.TIRAMISU)
intent?.getParcelableExtra(EXTRA_KEY_EVENT, KeyEvent::class.java)
} else {
else {
@Suppress("DEPRECATION")
intent?.getParcelableExtra(EXTRA_KEY_EVENT)
}
Expand Down Expand Up @@ -797,6 +789,7 @@ class PlaybackService : MediaLibraryService() {
return super.onStartCommand(intent, flags, startId)
}
playable != null -> {
recreateMediaSessionIfNeeded()
Logd(TAG, "onStartCommand status: $status")
val allowStreamThisTime = intent?.getBooleanExtra(EXTRA_ALLOW_STREAM_THIS_TIME, false) ?: false
val allowStreamAlways = intent?.getBooleanExtra(EXTRA_ALLOW_STREAM_ALWAYS, false) ?: false
Expand Down Expand Up @@ -963,6 +956,7 @@ class PlaybackService : MediaLibraryService() {
}

private fun startPlayingFromPreferences() {
recreateMediaSessionIfNeeded()
scope.launch {
try {
withContext(Dispatchers.IO) { loadPlayableFromPreferences() }
Expand All @@ -975,7 +969,7 @@ class PlaybackService : MediaLibraryService() {
}

private fun startPlaying(allowStreamThisTime: Boolean) {
Logd(TAG, "startPlaying called $allowStreamThisTime")
Logd(TAG, "startPlaying called allowStreamThisTime: $allowStreamThisTime")
val media = curMedia ?: return

val localFeed = URLUtil.isContentUrl(media.getStreamUrl())
Expand All @@ -986,18 +980,17 @@ class PlaybackService : MediaLibraryService() {
return
}

if (media.getIdentifier() != curState.curMediaId) clearCurTempSpeed()
// TODO: this is redundant
// if (media.getIdentifier() != curState.curMediaId) clearCurTempSpeed()

mPlayer?.playMediaObject(media, streaming, startWhenPrepared = true, true)
recreateMediaSessionIfNeeded()
// recreateMediaSessionIfNeeded()
// val episode = (media as? EpisodeMedia)?.episode
// if (curMedia is EpisodeMedia && episode != null) addToQueue(true, episode)
}

fun clearCurTempSpeed() {
curState = upsertBlk(curState) {
it.curTempSpeed = FeedPreferences.SPEED_USE_GLOBAL
}
curState = upsertBlk(curState) { it.curTempSpeed = FeedPreferences.SPEED_USE_GLOBAL }
}

private var eventSink: Job? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ac.mdiq.podcini.ui.actions.menuhandler
package ac.mdiq.podcini.ui.actions.handler

import ac.mdiq.podcini.R
import ac.mdiq.podcini.net.sync.SynchronizationSettings.isProviderConnected
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ac.mdiq.podcini.ui.actions
package ac.mdiq.podcini.ui.actions.handler

import ac.mdiq.podcini.R
import ac.mdiq.podcini.databinding.SelectQueueDialogBinding
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ac.mdiq.podcini.ui.actions.menuhandler
package ac.mdiq.podcini.ui.actions.handler

import android.view.Menu
import android.view.MenuItem
Expand Down

This file was deleted.

Loading

0 comments on commit 782c582

Please sign in to comment.