Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

temp #209

Merged
merged 1 commit into from
Dec 1, 2024
Merged

temp #209

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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fun Project.configureComposeMultiplatform(
commonMain.dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.material3)
implementation(compose.animation)
implementation(compose.ui)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.andannn.melodify
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Surface
import androidx.compose.material3.VerticalDivider
Expand All @@ -11,6 +13,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.MenuBar
import androidx.compose.ui.window.Window
import com.andannn.melodify.core.data.model.AudioItemModel
Expand Down Expand Up @@ -47,26 +50,27 @@ fun MelodifyDeskTopApp() {
fun MainWindowContent(
modifier: Modifier = Modifier,
) {
Row(modifier = modifier.fillMaxSize()) {
LeftSidePaneSector(
modifier = Modifier.weight(1f)
)

VerticalDivider()
Column(
modifier = Modifier.fillMaxSize(),
) {

Column(
modifier = Modifier.weight(2f),
) {
TabWithContentSector(
Row(modifier = modifier.weight(1f)) {
LeftSidePaneSector(
modifier = Modifier.weight(1f)
)

HorizontalDivider()
VerticalDivider()

PlayerSector(
modifier = Modifier
TabWithContentSector(
modifier = Modifier.weight(2f)
)
}

HorizontalDivider()

PlayerSector(
modifier = Modifier
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class MediaControllerRepositoryImpl(
private val mediaBrowser
get() = mediaBrowserManager.mediaBrowser

override val duration: Long
override val currentDuration: Long
get() = mediaBrowser.duration

override fun playMediaList(mediaList: List<AudioItemModel>, index: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import kotlinx.coroutines.flow.Flow
import kotlin.time.Duration

interface MediaControllerRepository {
val duration: Long?
val currentDuration: Long?

fun playMediaList(mediaList: List<AudioItemModel>, index: Int)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.andannn.melodify.core.data.repository

import com.andannn.melodify.core.data.model.CustomTab
import com.andannn.melodify.core.data.model.MediaPreviewMode
import com.andannn.melodify.core.data.model.UserSetting
import kotlinx.coroutines.flow.Flow

Expand All @@ -10,7 +9,5 @@ interface UserPreferenceRepository {

val currentCustomTabsFlow: Flow<List<CustomTab>>

suspend fun setPreviewMode(previewMode: MediaPreviewMode)

suspend fun updateCurrentCustomTabs(currentCustomTabs: List<CustomTab>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ class UserPreferenceRepositoryImpl(
.getCustomTabsFlow()
.map { it.mapToCustomTabModel() }

override suspend fun setPreviewMode(previewMode: MediaPreviewMode) {
preferences.setMediaPreviewMode(previewMode.toIntValue())
}

override suspend fun updateCurrentCustomTabs(currentCustomTabs: List<CustomTab>) {
userDataDao.clearAndInsertCustomTabs(
currentCustomTabs.map { it.toEntity() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private const val TAG = "MediaControllerRepository"

internal class FakeMediaControllerRepositoryImpl(
) : MediaControllerRepository {
override val duration: Long?
override val currentDuration: Long?
get() = 0L

override fun playMediaList(mediaList: List<AudioItemModel>, index: Int) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package com.andannn.melodify.core.data.di

import com.andannn.melodify.core.data.repository.MediaControllerRepository
import com.andannn.melodify.core.data.repository.MediaControllerRepositoryImpl
import com.andannn.melodify.core.data.repository.PlayerStateMonitoryRepository
import com.andannn.melodify.core.data.repository.fake.FakeMediaControllerRepositoryImpl
import com.andannn.melodify.core.data.repository.fake.FakePlayerStateMonitoryRepositoryImpl
import com.andannn.melodify.core.data.repository.PlayerStateMonitoryRepositoryImpl
import org.koin.core.module.Module
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.bind
import org.koin.dsl.module

internal actual val platformDataModule: Module = module {
singleOf(::FakeMediaControllerRepositoryImpl).bind(
singleOf(::MediaControllerRepositoryImpl).bind(
MediaControllerRepository::class
)
singleOf(::FakePlayerStateMonitoryRepositoryImpl).bind(
singleOf(::PlayerStateMonitoryRepositoryImpl).bind(
PlayerStateMonitoryRepository::class
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.andannn.melodify.core.data.repository

import com.andannn.melodify.core.data.model.AudioItemModel
import com.andannn.melodify.core.data.model.PlayMode
import com.andannn.melodify.core.player.VlcPlayer
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import kotlin.time.Duration

internal class MediaControllerRepositoryImpl(
private val vlcPlayer: VlcPlayer
) : MediaControllerRepository {
override val currentDuration: Long
get() = vlcPlayer.currentDurationMs

override fun playMediaList(mediaList: List<AudioItemModel>, index: Int) {
vlcPlayer.playMediaList(
mediaList.map { it.source },
index
)
}

override fun seekToNext() = vlcPlayer.seekToNext()

override fun seekToPrevious() = vlcPlayer.seekToPrevious()

override fun seekMediaItem(mediaItemIndex: Int, positionMs: Long) =
vlcPlayer.seekMediaItem(mediaItemIndex, positionMs)

override fun seekToTime(time: Long) = vlcPlayer.seekToTime(time)

override fun setPlayMode(mode: PlayMode) {
}

override fun setShuffleModeEnabled(enable: Boolean) {
}

override fun play() = vlcPlayer.play()

override fun pause() = vlcPlayer.pause()

override fun addMediaItems(index: Int, mediaItems: List<AudioItemModel>) =
vlcPlayer.addMediaItems(
index = index,
mrls = mediaItems.map { it.source },
)

override fun moveMediaItem(from: Int, to: Int) = vlcPlayer.moveMediaItem(from, to)

override fun removeMediaItem(index: Int) = vlcPlayer.removeMediaItem(index)

override fun isCounting(): Boolean {
return false
}

override fun observeIsCounting(): Flow<Boolean> {
return flowOf(false)
}

override fun observeRemainTime(): Flow<Duration> {
return flowOf()
}

override fun startSleepTimer(duration: Duration) {
}

override fun cancelSleepTimer() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.andannn.melodify.core.data.repository

import com.andannn.melodify.core.data.model.AudioItemModel
import com.andannn.melodify.core.data.model.PlayMode
import com.andannn.melodify.core.data.util.toAppItem
import com.andannn.melodify.core.database.dao.MediaLibraryDao
import com.andannn.melodify.core.player.VlcPlayer
import com.andannn.melodify.core.player.PlayerState
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map

internal class PlayerStateMonitoryRepositoryImpl(
private val vlcPlayer: VlcPlayer,
private val libraryDao: MediaLibraryDao
) : PlayerStateMonitoryRepository {
override val currentPositionMs: Long = vlcPlayer.currentPositionMs

override val playingIndexInQueue: Int = vlcPlayer.playingIndexInQueue

override val playListQueue: List<AudioItemModel> = emptyList()

override val playingMediaStateFlow: Flow<AudioItemModel?> = vlcPlayer.observePlayingMediaMrl()
.map { mrl ->
if (mrl == null) {
return@map null
}
libraryDao.getMediaByMediaIds(listOf(mrl.hashCode().toLong().toString())).firstOrNull()?.toAppItem()
}

override val playListQueueStateFlow: Flow<List<AudioItemModel>> = flowOf(emptyList())

override fun observeIsShuffle(): StateFlow<Boolean> {
return MutableStateFlow(false)
}

override val playMode: PlayMode
get() = PlayMode.REPEAT_ALL

override fun observePlayMode() = flowOf(PlayMode.REPEAT_ALL)

override fun observeIsPlaying(): Flow<Boolean> = vlcPlayer.observePlayerState()
.map {
it is PlayerState.Playing
}
.distinctUntilChanged()

override fun observeProgressFactor(): Flow<Float> = vlcPlayer.observeProgressFactor()
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ interface MediaLibraryDao {
@Query("SELECT * FROM ${Tables.LIBRARY_MEDIA} WHERE ${MediaColumns.ID} IN (:mediaIds)")
suspend fun getMediaByMediaIds(mediaIds: List<String>): List<MediaEntity>

@Query("SELECT * FROM ${Tables.LIBRARY_MEDIA} WHERE ${MediaColumns.ID} IN (:mediaIds)")
fun getMediaByMediaIdsFlow(mediaIds: List<String>): Flow<List<MediaEntity>>

@Transaction
suspend fun clearAndInsertLibrary(
albums: List<AlbumEntity>,
Expand Down
4 changes: 4 additions & 0 deletions core/player/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ kotlin {
implementation(libs.androidx.media3.exoplayer)
implementation(libs.androidx.media3.session)
}

desktopMain.dependencies {
implementation(libs.vlcj)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.koin.core.module.dsl.singleOf
import org.koin.dsl.bind
import org.koin.dsl.module

internal actual val platformPlayerModule: Module = module {
internal actual val platformVlcPlayerModule: Module = module {
singleOf(::PlayerWrapperImpl).bind(PlayerWrapper::class)
singleOf(::MediaBrowserManagerImpl).bind(MediaBrowserManager::class)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import org.koin.dsl.bind
import org.koin.dsl.module

val playerModule : Module = module {
includes(platformPlayerModule)
includes(platformVlcPlayerModule)
singleOf(::SleepTimerControllerImpl).bind(SleepTimerController::class)
}

internal expect val platformPlayerModule : Module
internal expect val platformVlcPlayerModule : Module
Loading
Loading