Skip to content

Commit

Permalink
[UPDATE] Enhanced Playback and Widget Functionality, Updated Dependen…
Browse files Browse the repository at this point in the history
…cies

- Playback: Added `Player.REPEAT_MODE_ALL` support to
 `NowPlaying` intent extras.
- Playback: Updated widget events in `Playback` service to include `UPDATE_EVENTS` which include various events related to playback, timeline etc.
- Dependencies: Updated Compose to `1.8.0-alpha08`, Firebase Analytics to `22.2.0` and Crashlytics to `19.4.0`, Activity Compose to `1.10.0`.
- Gradle: Updated `versionCode` to `182` and `versionName` to `3.3.0-alpha02`.
  • Loading branch information
iZakirSheikh committed Jan 21, 2025
1 parent e37e7e1 commit dcdf39c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 29 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ android {
applicationId = "com.prime.player"
minSdk = 21
targetSdk = 35
versionCode = 181
versionName = "3.3.0-alpha01"
versionCode = 182
versionName = "3.3.0-beta01"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables { useSupportLibrary = true }
// init different config fields.
Expand Down
10 changes: 4 additions & 6 deletions app/src/main/res/values/what_s_new.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@

<string name="what_s_new_toast" translatable="false"><b>What\'s New</b>
<font color='grey'>
\n Added support for Spanish language.
\n Added a link to help translate the app.
\n Fixed the navigation bug causing the backstack to clear.
\n Bug fixes and performance improvements.
\n 🚀 <b>Introduced a Brand-New In-App Video Browser Screen:</b> Seamlessly browse and
play videos directly within the app.
\n We\'ve enhanced the functionality of the app.
\n We\'re utilizing the new, advanced NowPlaying API for real-time updates regarding playback metadata state.
\n We\'ve added a new Dynamic Widget that automatically adjusts to size.
\n More App Widget styles are coming soon.
</font>
</string>

Expand Down
9 changes: 8 additions & 1 deletion core/src/main/java/com/zs/core/playback/NowPlaying.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.util.Log
import androidx.media3.common.C
import androidx.media3.common.Player
Expand Down Expand Up @@ -62,6 +63,9 @@ value class NowPlaying(private val value: Intent) {
@JvmStatic
val EXTRA_SEEK_PCT = "com.prime.player.extra.SEEK_TO"

@JvmStatic
val EXTRA_REPEAT_MODE = "com.prime.player.action.REPEAT_MODE"

/**
* Constructs the widget update intent from a [Player].
*/
Expand All @@ -83,6 +87,7 @@ value class NowPlaying(private val value: Intent) {
putExtra(EXTRAS_PLAY_WHEN_READY, player.playWhenReady)
putExtra(EXTRA_WHEN, System.currentTimeMillis())
putExtra(EXTRA_SPEED, player.playbackParameters.speed)
putExtra(EXTRA_REPEAT_MODE, player.repeatMode)
}
}

Expand All @@ -97,7 +102,7 @@ value class NowPlaying(private val value: Intent) {
inline fun trySend(ctx: Context, action: String? = null, args: Intent.() -> Unit = {}) {
try {
val intent = Intent(action, null, ctx, Playback::class.java).apply(args)
ctx.startService(intent)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) ctx.startForegroundService(intent) else ctx.startService(intent)
} catch (i: Exception) {
Log.d("NowPlaying", "trySend: ${i.message}")
}
Expand All @@ -122,6 +127,8 @@ value class NowPlaying(private val value: Intent) {
get() = value.getBooleanExtra(EXTRAS_PLAY_WHEN_READY, false)
val speed
get() = value.getFloatExtra(EXTRA_SPEED, 1f)
val repeatMode
get() = value.getIntExtra(EXTRA_REPEAT_MODE, Player.REPEAT_MODE_ALL)

val playing get() = playWhenReady && state != Player.STATE_ENDED && state != Player.STATE_IDLE
}
41 changes: 25 additions & 16 deletions core/src/main/java/com/zs/core/playback/Playback.kt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ class Playback : MediaLibraryService(), Callback, Player.Listener {

//
private val LIST_ITEM_DELIMITER = ';'

/**
* Player events that trigger widget updates.
*
* The widget updates its state upon receiving any of these events,
* reflecting changes to playback, timeline, or other player properties.
*/
internal val UPDATE_EVENTS = intArrayOf(
Player.EVENT_TIMELINE_CHANGED,
Player.EVENT_PLAYBACK_STATE_CHANGED,
Player.EVENT_REPEAT_MODE_CHANGED,
Player.EVENT_IS_PLAYING_CHANGED,
Player.EVENT_IS_LOADING_CHANGED,
Player.EVENT_PLAYBACK_PARAMETERS_CHANGED,
Player.EVENT_SHUFFLE_MODE_ENABLED_CHANGED,
Player.EVENT_MEDIA_ITEM_TRANSITION
)
}

private val scope = CoroutineScope(Dispatchers.Main + SupervisorJob())
Expand Down Expand Up @@ -264,8 +281,11 @@ class Playback : MediaLibraryService(), Callback, Player.Listener {
sendBroadcast(NowPlaying.from(this, player))
return super.onStartCommand(intent, flags, startId)
}
if (player.playbackState != Player.STATE_READY)
if (player.playbackState != Player.STATE_READY) {
// FIX-ME Here we assume that session hasn't been added.
addSession(session)
player.prepare()
}
// if action is null; implies notification update requested
when(action){
NowPlaying.ACTION_TOGGLE_PLAY -> player.playWhenReady = !player.playWhenReady
Expand Down Expand Up @@ -457,18 +477,9 @@ class Playback : MediaLibraryService(), Callback, Player.Listener {
}
}

/**
* Called when an update to the media session's notification is required, possibly to start it in foreground mode.
*
* @param session The media session.
* @param startInForegroundRequired True if the notification should be started in foreground mode.
*/
override fun onUpdateNotification(
session: MediaSession,
startInForegroundRequired: Boolean
) {
super.onUpdateNotification(session, startInForegroundRequired)
// TODO - Send notification from call-site of each change.
override fun onEvents(player: Player, events: Player.Events) {
if (!events.containsAny(*UPDATE_EVENTS))
return
sendBroadcast(NowPlaying.from(this, player))
}

Expand All @@ -477,9 +488,7 @@ class Playback : MediaLibraryService(), Callback, Player.Listener {
*
* @param error The playback exception representing the error.
*/
override fun onPlayerError(
error: PlaybackException
) {
override fun onPlayerError(error: PlaybackException) {
// Display a simple toast message indicating an unplayable file
Toast.makeText(this, "Unplayable file", Toast.LENGTH_SHORT).show()
// You may choose to handle the error here or take other actions like seeking to the next media item
Expand Down
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
agp = "8.8.0"
kotlin = "2.1.0"
compose = "1.8.0-alpha07"
compose = "1.8.0-alpha08"
media3 = "1.5.1"
toolkit = "v2.2.5"
material_icons = "1.7.6"
Expand Down Expand Up @@ -55,8 +55,8 @@ accompanist-adaptive = { module = "com.google.accompanist:accompanist-adaptive",


# Firebase
firebase-analytics-ktx = { module = "com.google.firebase:firebase-analytics-ktx", version = "22.1.2" }
firebase-crashlytics-ktx = { module = "com.google.firebase:firebase-crashlytics-ktx", version = "19.3.0" }
firebase-analytics-ktx = { module = "com.google.firebase:firebase-analytics-ktx", version = "22.2.0" }
firebase-crashlytics-ktx = { module = "com.google.firebase:firebase-crashlytics-ktx", version = "19.4.0" }

#Compose preview
ui-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "compose" }
Expand Down Expand Up @@ -88,7 +88,7 @@ iron_source_ad_qaulity = { module = "com.ironsource:adqualitysdk", version = "7.
unity_adapter = { module = "com.ironsource.adapters:unityadsadapter", version = "4.3.40" }

androidx-window = { group = "androidx.window", name = "window", version = "1.3.0" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version = "1.9.3" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version = "1.10.0" }
androidx-core-splashscreen = { module = "androidx.core:core-splashscreen", version = "1.0.1" }
androidx-startup-runtime = { module = "androidx.startup:startup-runtime", version = "1.2.0" }
lottie-compose = { module = "com.airbnb.android:lottie-compose", version = "6.6.2" }
Expand Down

0 comments on commit dcdf39c

Please sign in to comment.