Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ android {
buildFeatures {
compose = true
viewBinding = true
buildConfig = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.3"
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/cattailsw/mediaplayer/ExoHolderVM.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ sealed class PlayerState {
class ExoHolderVM(
private val okHttpClient: OkHttpClient = DIGraph.okHttpClient,
) : ViewModel() {

// TODO find a better place for this; the flow is placed here so I don't have to change navgraph
private val _historyFlow: MutableStateFlow<List<PlaybackHistory>> = MutableStateFlow<List<PlaybackHistory>>(listOf(
PlaybackHistory(Uri.parse("test"), 1L, 0),
PlaybackHistory(Uri.parse("test2"), 2L, 1),
PlaybackHistory(Uri.parse("test3"), 3L, 0)
))
val historyFlow: StateFlow<List<PlaybackHistory>> = _historyFlow

private var _exoPlayer: ExoPlayer? = null
private var currentMediaItem: MediaItem? = null

Expand Down
105 changes: 95 additions & 10 deletions app/src/main/java/com/cattailsw/mediaplayer/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.cattailsw.mediaplayer

import android.content.Intent.ACTION_VIEW
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.view.WindowManager
Expand All @@ -11,25 +12,43 @@ import androidx.activity.compose.setContent
import androidx.activity.result.PickVisualMediaRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.view.WindowCompat
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.navigation.NavDeepLink
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navDeepLink
import com.cattailsw.mediaplayer.ui.theme.CMediaPlayerTheme
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import androidx.core.net.toUri


private const val TAG = "MainActivity"
Expand All @@ -41,10 +60,10 @@ class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

WindowCompat.setDecorFitsSystemWindows(window, false)

exoHolder.initPlayer(applicationContext)
val deepLink: NavDeepLink = NavDeepLink.Builder().setAction(ACTION_VIEW)
.setMimeType("video/*")
.build()

lifecycleScope.launch {
// keep screen on when player is in play state.
Expand Down Expand Up @@ -75,7 +94,11 @@ class MainActivity : ComponentActivity() {
val navController = rememberNavController()

MainNavGraph(
exoHolder = exoHolder, extDeepLink = deepLink, navController = navController,
exoHolder = exoHolder, extDeepLink = navDeepLink {
mimeType = "video/*"
action = Intent.ACTION_VIEW
},
navController = navController,
mainOpenAction = { viewModel.openLocalFileBrowser() },
exoScreenBackAction = {
exoHolder.stop()
Expand Down Expand Up @@ -113,16 +136,21 @@ class MainActivity : ComponentActivity() {

@Composable
fun MainScreen(
playbackHistoryItems: StateFlow<List<PlaybackHistory>>,
openLocal: () -> Unit,
launch: () -> Unit
launchPlayer: () -> Unit
) {

CMediaPlayerTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
modifier = Modifier.fillMaxSize(),//.safeDrawingPadding(),
color = MaterialTheme.colorScheme.background
) {
Column(
modifier = Modifier
.padding(top = 16.dp, start = 8.dp, end = 8.dp, bottom = 0.dp)
.systemBarsPadding().fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally
) {

Expand All @@ -131,21 +159,78 @@ fun MainScreen(
}

Button(
launch
launchPlayer
) {
Text("launch player")
}

PlaybackHistory(playbackHistoryItems)
}
}
}

}

@Composable
fun PlaybackHistory(
playbackHistory: StateFlow<List<PlaybackHistory>>,
modifier: Modifier = Modifier,
onItemClick: (uri: Uri) -> Unit = {}
) {
val historyItems: List<PlaybackHistory> by playbackHistory.collectAsState()

Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = modifier.background(color=MaterialTheme.colorScheme.primaryContainer).fillMaxSize()
) {
Text("Playback History", style=MaterialTheme.typography.titleLarge)
if (historyItems.isEmpty()) {
Text("No Playback History", style=MaterialTheme.typography.bodyMedium, modifier=Modifier.padding(16.dp))
} else {
LazyColumn {
items(historyItems) { item ->
HistoryItem(
item = item,
modifier = Modifier.clickable(onClick = { onItemClick(item.uri) })
)
}
}
}
}
}

@Composable
fun HistoryItem(
item: PlaybackHistory,
modifier: Modifier = Modifier
) {
Row(modifier = modifier.fillMaxWidth()) {
Box(modifier = Modifier.padding(4.dp)
// placeholder for a thumbnail, remove when we actually do read from uri
.fillMaxWidth(0.25f)
.aspectRatio(16f/9f)
.background(Color.Gray)) {
// pass
Text(item.uri.toString(), style=MaterialTheme.typography.bodySmall)
}
Column(modifier=Modifier.fillMaxWidth()) {
Text(item.uri.toString(), style=MaterialTheme.typography.titleMedium)
Text("Last Played: ${item.lastTimestamp}, Playback Count: ${item.playbackCount}", style=MaterialTheme.typography.bodySmall)
}
}
}


@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
val list = remember { MutableStateFlow(listOf<PlaybackHistory>(
PlaybackHistory("test".toUri(), 1L, 0),
PlaybackHistory("test2".toUri(), 2L, 1),
PlaybackHistory("test3".toUri(), 3L, 0)
)) }

CMediaPlayerTheme {
MainScreen({}, {})
MainScreen(list, {}, {})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ fun MainNavGraph(
) {
composable(route = PlayerDestinations.HOME) {
MainScreen(
playbackHistoryItems = exoHolder.historyFlow,
openLocal = mainOpenAction,
launch = {navController.navigate(PlayerDestinations.DBG_MEDIA)}
launchPlayer = {navController.navigate(PlayerDestinations.DBG_MEDIA)}
)
}
composable(route = PlayerDestinations.EXT_MEDIA, deepLinks = listOf(extDeepLink)) {
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/cattailsw/mediaplayer/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ sealed class MainState {
object ErrorOpen: MainState()
object OpenFile: MainState()
data class LaunchMedia(val uri: Uri): MainState()
}
}

data class PlaybackHistory(val uri: Uri, val lastTimestamp: Long = System.currentTimeMillis(), val playbackCount:Int = 0)
6 changes: 3 additions & 3 deletions app/src/main/java/com/cattailsw/mediaplayer/ui/theme/Type.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ val Typography = Typography(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp
)
/* Other default text styles to override
),
/* Other default text styles to override*/
titleLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 22.sp,
lineHeight = 28.sp,
letterSpacing = 0.sp
),
)/*,
labelSmall = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Medium,
Expand Down
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ kotlin.code.style=official
android.nonTransitiveRClass=true

kotlin.daemon.jvm.options=-Xmx8g
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
android.nonFinalResIds=true
org.gradle.configuration-cache=true
14 changes: 7 additions & 7 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[versions]
agp = "8.8.0"
agp = "8.8.2"
kotlin = "2.1.0"
core = "1.15.0"
compose = "1.7.6"
compose_material_version = "1.7.6"
compose = "1.7.8"
compose_material_version = "1.7.8"
compose_materia3_version = "1.3.1"
compose_compiler = "1.4.4"
lifecycle = "2.8.7"
navigation = "2.8.5"
navigation = "2.8.8"
media3 = "1.5.1"
okhttp3 = "4.12.0"
activity_compose = "1.10.0"
composeBom = "2025.01.00"
fragment = "1.8.5"
activity_compose = "1.10.1"
composeBom = "2025.02.00"
fragment = "1.8.6"
junit4 = "4.13.2"

[libraries]
Expand Down