Skip to content

Commit

Permalink
added prev and next buttons to player controls using custom layout (n…
Browse files Browse the repository at this point in the history
…eeds work); added a lite flavour
  • Loading branch information
Leonidius20 committed Aug 11, 2024
1 parent b2ada44 commit 17794ee
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 3 deletions.
18 changes: 18 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ android {
}

testOptions.unitTests.isIncludeAndroidResources = true

flavorDimensions += "version"

productFlavors {

create("lite") {
dimension = "version"
applicationIdSuffix = ".lite"
versionNameSuffix = "-lite"
}

create("full") {
dimension = "version"
}

}
}

dependencies {
Expand Down Expand Up @@ -84,4 +100,6 @@ dependencies {
implementation(libs.androidx.media3.ui)
implementation(libs.androidx.media3.exoplayer)
implementation(libs.androidx.media3.session)

// todo: if flavour = full, include AAP framework
}
5 changes: 5 additions & 0 deletions app/src/full/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Recording Studio</string>
<string name="app_name_short">Rec Studio</string>
</resources>
5 changes: 5 additions & 0 deletions app/src/lite/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Recording Studio Lite</string>
<string name="app_name_short">Rec Studio Lite</string>
</resources>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.leonidius20.recorder.ui.recordings_list.playback
package io.github.leonidius20.recorder.data.playback

import android.content.ComponentName
import android.content.Context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class RecorderService : LifecycleService() {
.setContentTitle("Recording in progress")
.setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE)
.setPriority(NotificationCompat.PRIORITY_LOW)
.setSilent(true)
.build()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.media3.common.MediaItem
import androidx.media3.common.MediaMetadata
import androidx.media3.common.Player
import androidx.media3.session.MediaController
import androidx.media3.session.SessionToken
import androidx.recyclerview.widget.DiffUtil
Expand Down Expand Up @@ -92,6 +93,8 @@ class RecordingsListFragment : Fragment() {
adapter.setData(recordings)
binding.recordingList.scrollToPosition(0)

// todo: use payloads to update file names

}

// this has to happen every time that we go to this fragment. However
Expand Down Expand Up @@ -331,4 +334,8 @@ class RecordingsListFragment : Fragment() {
}
}

fun attachPlayerToView(player: Player) {
binding.playerView.player = player
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.github.leonidius20.recorder.ui.recordings_list.playback

import android.content.ComponentName
import android.content.Context
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.media3.common.MediaItem
import androidx.media3.common.MediaMetadata
import androidx.media3.session.MediaController
import androidx.media3.session.SessionToken
import com.google.common.util.concurrent.ListenableFuture
import com.google.common.util.concurrent.MoreExecutors
import dagger.hilt.android.qualifiers.ApplicationContext
import io.github.leonidius20.recorder.data.playback.PlaybackService
import io.github.leonidius20.recorder.ui.recordings_list.RecordingsListFragment

/*class PlaybackControls(
@ApplicationContext private val context: Context,
): DefaultLifecycleObserver {
private var mediaController: MediaController? = null
private var controllerFuture: ListenableFuture<MediaController>? = null
override fun onStart(owner: LifecycleOwner) {
super.onStart(owner)
val sessionToken = SessionToken(context, ComponentName(context, PlaybackService::class.java))
val factory = MediaController.Builder(context, sessionToken).buildAsync()
controllerFuture = factory
factory.addListener( {
mediaController = factory?.let {
if (it.isDone)
it.get()
else
null
}
(owner as RecordingsListFragment).attachPlayerToView(mediaController!!)
viewModel.recordings.value!!.forEach { recording ->
mediaController?.addMediaItem(
MediaItem.Builder().setUri(recording.uri).setMediaMetadata(
MediaMetadata.Builder().setDisplayTitle(recording.name).build()
).build()
)
}
mediaController?.prepare()
}, MoreExecutors.directExecutor())
}
}*/
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_recordings_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
android:layout_width="match_parent"
app:surface_type="none"
app:hide_on_touch="false"
app:controller_layout_id="@layout/playback_controls"
android:layout_height="64dp"/>
<!-- todo change the height of the controls -->
</androidx.constraintlayout.widget.ConstraintLayout>
Expand Down
66 changes: 66 additions & 0 deletions app/src/main/res/layout/playback_controls.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layoutDirection="ltr"
android:background="@color/md_theme_secondaryContainer"
android:orientation="vertical"
tools:targetApi="28">

<!--
docs regarding the IDs used here:
https://github.com/google/ExoPlayer/blob/release-v2/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerControlView.java
-->

<LinearLayout

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="4dp"
android:orientation="horizontal">

<ImageButton
android:id="@id/exo_prev"
style="@style/ExoMediaButton.Previous"/>

<ImageButton android:id="@id/exo_play_pause"
style="@style/ExoMediaButton.Play"/>

<ImageButton
android:id="@id/exo_next"
style="@style/ExoMediaButton.Next"/>

<!-- todo: slider for time -->




</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@id/exo_position"/>

<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@id/exo_progress_placeholder"/>


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@id/exo_duration"/>

</LinearLayout>

</LinearLayout>
3 changes: 1 addition & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<resources>
<string name="app_name">Recording Studio</string>
<string name="app_name_short">Rec Studio</string>

<string name="nav_title_record">Record</string>
<string name="nav_title_recordings">Recordings</string>
<string name="nav_title_settings">Settings</string>
Expand Down

0 comments on commit 17794ee

Please sign in to comment.