diff --git a/MusicPlayerV2-GUI/src/App.vue b/MusicPlayerV2-GUI/src/App.vue index 5358c04..c1c2498 100644 --- a/MusicPlayerV2-GUI/src/App.vue +++ b/MusicPlayerV2-GUI/src/App.vue @@ -36,6 +36,7 @@ --footer-background: rgb(233, 233, 233); --accent-background: rgb(195, 235, 243); --loading-color: rgb(167, 167, 167); + --slider-color: rgb(119, 132, 255); } :root.dark { @@ -50,6 +51,7 @@ --footer-background: rgb(53, 53, 53); --accent-background: rgb(24, 12, 58); --loading-color: rgb(65, 65, 65); + --slider-color: rgb(119, 132, 255); } @media ( prefers-color-scheme: dark ) { @@ -65,6 +67,7 @@ --footer-background: rgb(53, 53, 53); --accent-background: rgb(24, 12, 58); --loading-color: rgb(65, 65, 65); + --slider-color: rgb(119, 132, 255); } } diff --git a/MusicPlayerV2-GUI/src/components/playerView.vue b/MusicPlayerV2-GUI/src/components/playerView.vue index 48dbb18..2b74006 100644 --- a/MusicPlayerV2-GUI/src/components/playerView.vue +++ b/MusicPlayerV2-GUI/src/components/playerView.vue @@ -1,26 +1,39 @@ @@ -32,27 +45,31 @@ import { ref, type Ref } from 'vue'; import playlistView from '@/components/playlistView.vue'; import MusicKitJSWrapper from '@/scripts/music-player'; + import sliderView from './sliderView.vue'; import type { Song } from '@/scripts/song'; const isPlaying = ref( false ); const repeatMode = ref( '' ); const shuffleMode = ref( '' ); const currentlyPlayingSongName = ref( 'Not playing' ); + const currentlyPlayingSongIndex = ref( 0 ); const clickCountForward = ref( 0 ); const clickCountBack = ref( 0 ); const isShowingFullScreenPlayer = ref( false ); const player = new MusicKitJSWrapper(); const playlist: Ref = ref( [] ); const coverArt = ref( '' ); - const nicePlaybackPos = ref( '' ); - const niceDuration = ref( '' ); + const nicePlaybackPos = ref( '00:00' ); + const niceDuration = ref( '00:00' ); const isShowingRemainingTime = ref( false ); + const currentlyPlayingSongArtist = ref( '' ); + const pos = ref( 0 ); + const duration = ref( 0 ); const emits = defineEmits( [ 'playerStateChange' ] ); const playPause = () => { isPlaying.value = !isPlaying.value; - // TODO: Execute function on player if ( isPlaying.value ) { player.control( 'play' ); startProgressTracker(); @@ -63,7 +80,15 @@ } const control = ( action: string ) => { - if ( action === 'repeat' ) { + if ( action === 'pause' ) { + isPlaying.value = false; + player.control( 'pause' ); + stopProgressTracker(); + } else if ( action === 'play' ) { + isPlaying.value = true; + player.control( 'play' ); + startProgressTracker(); + } else if ( action === 'repeat' ) { if ( repeatMode.value === '' ) { repeatMode.value = '_on'; player.setRepeatMode( 'all' ); @@ -82,6 +107,7 @@ shuffleMode.value = ''; player.setShuffle( false ); } + getDetails(); } else if ( action === 'forward' ) { clickCountForward.value += 1; player.control( 'skip-10' ); @@ -91,6 +117,8 @@ } else if ( action === 'next' ) { stopProgressTracker(); player.control( 'next' ); + coverArt.value = ''; + currentlyPlayingSongArtist.value = ''; currentlyPlayingSongName.value = 'Loading...'; setTimeout( () => { getDetails(); @@ -99,6 +127,8 @@ } else if ( action === 'previous' ) { stopProgressTracker(); player.control( 'previous' ); + coverArt.value = ''; + currentlyPlayingSongArtist.value = ''; currentlyPlayingSongName.value = 'Loading...'; setTimeout( () => { getDetails(); @@ -135,6 +165,8 @@ } const selectPlaylist = ( id: string ) => { + currentlyPlayingSongArtist.value = ''; + coverArt.value = ''; currentlyPlayingSongName.value = 'Loading...'; player.setPlaylistByID( id ).then( () => { isPlaying.value = true; @@ -149,14 +181,36 @@ const details = player.getPlayingSong(); currentlyPlayingSongName.value = details.title; coverArt.value = details.cover; - // console.log( player.getQueue() ); - playlist.value = player.getPlaylist(); + currentlyPlayingSongIndex.value = player.getPlayingSongID(); + playlist.value = player.getQueue(); + console.log( playlist.value ); + currentlyPlayingSongArtist.value = details.artist; + } + + const playSong = ( id: string ) => { + const p = player.getPlaylist(); + currentlyPlayingSongArtist.value = ''; + coverArt.value = ''; + currentlyPlayingSongName.value = 'Loading...'; + stopProgressTracker(); + for ( const s in p ) { + if ( p[ s ].id === id ) { + player.prepare( parseInt( s ) ); + setTimeout( () => { + getDetails(); + startProgressTracker(); + }, 2000 ); + break; + } + } } let progressTracker = 0; const startProgressTracker = () => { + isPlaying.value = true; const playingSong = player.getPlayingSong(); + duration.value = playingSong.duration; const minuteCounts = Math.floor( ( playingSong.duration ) / 60 ); niceDuration.value = String( minuteCounts ) + ':'; if ( ( '' + minuteCounts ).length === 1 ) { @@ -169,17 +223,18 @@ niceDuration.value += secondCounts; } progressTracker = setInterval( () => { - const pos = player.getPlaybackPos(); - if ( pos > playingSong.duration - 1 ) { + pos.value = player.getPlaybackPos(); + if ( pos.value > playingSong.duration - 1 ) { + // TODO: repeat control( 'next' ); } - const minuteCount = Math.floor( pos / 60 ); + const minuteCount = Math.floor( pos.value / 60 ); nicePlaybackPos.value = minuteCount + ':'; if ( ( '' + minuteCount ).length === 1 ) { nicePlaybackPos.value = '0' + minuteCount + ':'; } - const secondCount = Math.floor( pos - minuteCount * 60 ); + const secondCount = Math.floor( pos.value - minuteCount * 60 ); if ( ( '' + secondCount ).length === 1 ) { nicePlaybackPos.value += '0' + secondCount; } else { @@ -187,12 +242,12 @@ } if ( isShowingRemainingTime.value ) { - const minuteCounts = Math.floor( ( playingSong.duration - pos ) / 60 ); + const minuteCounts = Math.floor( ( playingSong.duration - pos.value ) / 60 ); niceDuration.value = '-' + String( minuteCounts ) + ':'; if ( ( '' + minuteCounts ).length === 1 ) { niceDuration.value = '-0' + minuteCounts + ':'; } - const secondCounts = Math.floor( ( playingSong.duration - pos ) - minuteCounts * 60 ); + const secondCounts = Math.floor( ( playingSong.duration - pos.value ) - minuteCounts * 60 ); if ( ( '' + secondCounts ).length === 1 ) { niceDuration.value += '0' + secondCounts; } else { @@ -206,6 +261,7 @@ try { clearInterval( progressTracker ); } catch ( _ ) { /* empty */ } + isPlaying.value = false; } defineExpose( { @@ -229,7 +285,18 @@ transition: all 1s; } - .song-name { + .main-player { + height: 12vh; + width: 100%; + display: flex; + justify-content: center; + align-items: center; + flex-direction: row; + transition: all 1s; + position: relative + } + + .song-name-wrapper { cursor: pointer; margin-left: 10px; width: 100%; @@ -238,8 +305,12 @@ font-weight: bold; font-size: 1.25rem; display: flex; - align-items: center; - flex-direction: row; + flex-direction: column; + justify-content: center; + } + + .song-name { + margin: 0; } .logo-player { @@ -248,10 +319,6 @@ margin-left: 30px; } - .playlist-view { - overflow: scroll; - } - .player-hidden { height: 100%; } @@ -325,4 +392,37 @@ .pl-wrapper { height: 80vh; } + + .playback { + width: fit-content; + bottom: -20px; + left: 7%; + font-weight: normal; + font-size: 1rem; + } + + .playback.full-screen { + left: 30%; + position: absolute; + width: 40%; + } + + .playback-pos-wrapper { + width: 100%; + display: flex; + justify-content: center; + align-items: center; + } + + .playback-pos-wrapper p { + margin: 0; + } + + .playback-pos-wrapper.full-screen p { + margin-bottom: 15px; + } + + .playback-pos-wrapper.full-screen .playback-duration { + margin-left: auto; + } \ No newline at end of file diff --git a/MusicPlayerV2-GUI/src/components/playlistView.vue b/MusicPlayerV2-GUI/src/components/playlistView.vue index 8bc7021..c67ec06 100644 --- a/MusicPlayerV2-GUI/src/components/playlistView.vue +++ b/MusicPlayerV2-GUI/src/components/playlistView.vue @@ -1,9 +1,21 @@