Skip to content

Commit

Permalink
feat: player position
Browse files Browse the repository at this point in the history
  • Loading branch information
akdasa committed Mar 22, 2023
1 parent 17782a0 commit 6c9ab02
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@akdasa-studios/shlokas-uikit",
"version": "0.0.18",
"version": "0.0.19",
"files": [
"dist"
],
Expand Down
3 changes: 3 additions & 0 deletions src/AudioPlayer.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export default {
playing: {
control: { type: 'boolean' }
},
position: {
control: { type: 'number' }
}
},
};

Expand Down
8 changes: 5 additions & 3 deletions src/AudioPlayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ref, toRefs, watch, withDefaults, defineEmits } from 'vue'
export interface Props {
uri?: string,
playing?: boolean,
position?: number,
title?: string,
artist?: string,
album?: string,
Expand All @@ -31,7 +32,7 @@ export interface Emits {
}
const props = withDefaults(defineProps<Props>(), {
uri: '', playing: false, title: '', artist: '', album: '', loop: false
uri: '', playing: false, title: '', artist: '', album: '', loop: false, position:0
})
const emit = defineEmits<Emits>()
Expand All @@ -41,11 +42,11 @@ const emit = defineEmits<Emits>()
/* -------------------------------------------------------------------------- */
const audioRef = ref()
const { uri, title, artist, loop, album, playing } = toRefs(props)
const { uri, title, artist, loop, album, playing, position } = toRefs(props)
const player = useMediaControls(audioRef, { src: uri })
// If the audio file changes, stop the player
watch(uri, () => { player.playing.value = false })
watch(uri, () => { player.playing.value = false;player.playing.value = true })
watch([player.playing, player.currentTime], () => onPlayingStatusChanged())
// If the title or artist changes, update the media session
Expand All @@ -62,6 +63,7 @@ watch([title, artist], () => {
})
syncRef(playing, player.playing, { direction: 'ltr' })
syncRef(position, player.currentTime, { direction: 'both' })
/* -------------------------------------------------------------------------- */
/* Handlers */
Expand Down

0 comments on commit 6c9ab02

Please sign in to comment.