2021-01-16 12:12:44 +00:00
|
|
|
/*
|
|
|
|
* @copyright Copyright (c) 2021 Jonas Heinrich <onny@project-insanity.org>
|
|
|
|
*
|
|
|
|
* @author Jonas Heinrich <onny@project-insanity.org>
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-01-18 13:51:53 +00:00
|
|
|
import { Player } from './../services/Player'
|
|
|
|
const player = new Player()
|
|
|
|
|
2021-01-16 12:12:44 +00:00
|
|
|
export default ({
|
|
|
|
state: {
|
|
|
|
isPlaying: false,
|
|
|
|
isBuffering: false,
|
2021-01-19 21:34:48 +00:00
|
|
|
isPausing: false,
|
2021-03-07 10:45:35 +00:00
|
|
|
volume: 0.5,
|
|
|
|
oldVolume: null,
|
2021-01-16 12:12:44 +00:00
|
|
|
title: '',
|
|
|
|
},
|
2021-01-20 10:30:30 +00:00
|
|
|
getters: {
|
|
|
|
getPlaying: state => {
|
|
|
|
return state.isPlaying
|
|
|
|
},
|
|
|
|
getBuffering: state => {
|
|
|
|
return state.isBuffering
|
|
|
|
},
|
|
|
|
getVolume: state => {
|
|
|
|
return state.volume
|
|
|
|
},
|
|
|
|
getTitle: state => {
|
|
|
|
return state.title
|
|
|
|
},
|
|
|
|
},
|
2021-01-16 12:12:44 +00:00
|
|
|
mutations: {
|
|
|
|
setPlaying(state, playerState) {
|
|
|
|
state.isPlaying = playerState
|
|
|
|
},
|
2021-01-19 21:34:48 +00:00
|
|
|
setPausing(state, pauseState) {
|
|
|
|
state.isPausing = pauseState
|
|
|
|
},
|
2021-01-16 12:12:44 +00:00
|
|
|
setBuffering(state, bufferingState) {
|
|
|
|
state.isBuffering = bufferingState
|
|
|
|
},
|
|
|
|
setVolume(state, volume) {
|
|
|
|
state.volume = volume
|
|
|
|
localStorage.setItem('radio.volume', volume)
|
2021-01-20 10:30:30 +00:00
|
|
|
player.setVolume(state.volume)
|
2021-01-16 12:12:44 +00:00
|
|
|
},
|
|
|
|
toggleMute(state) {
|
2021-03-07 10:45:35 +00:00
|
|
|
if (parseFloat(state.volume)) {
|
2021-01-20 10:30:30 +00:00
|
|
|
state.oldVolume = state.volume
|
2021-01-16 12:12:44 +00:00
|
|
|
state.volume = 0
|
2021-03-07 10:45:35 +00:00
|
|
|
} else {
|
|
|
|
if (parseFloat(state.oldVolume)) {
|
|
|
|
state.volume = state.oldVolume
|
|
|
|
} else {
|
|
|
|
state.oldVolume = 0
|
|
|
|
state.volume = 1
|
|
|
|
}
|
2021-01-16 12:12:44 +00:00
|
|
|
}
|
2021-03-07 10:45:35 +00:00
|
|
|
localStorage.setItem('radio.volume', state.volume)
|
2021-01-20 10:30:30 +00:00
|
|
|
player.setVolume(state.volume)
|
2021-01-16 12:12:44 +00:00
|
|
|
},
|
|
|
|
togglePlay(state) {
|
|
|
|
if (state.isPlaying) {
|
|
|
|
state.isPlaying = false
|
|
|
|
state.isPaused = true
|
2021-01-20 10:40:05 +00:00
|
|
|
player.doPause()
|
2021-01-16 12:12:44 +00:00
|
|
|
} else {
|
|
|
|
state.isPlaying = true
|
|
|
|
state.isPaused = false
|
2021-01-20 10:40:05 +00:00
|
|
|
player.doResume()
|
2021-01-16 12:12:44 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
setTitle(state, title) {
|
|
|
|
state.title = title
|
|
|
|
},
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
setPlaying(context, playerState) {
|
|
|
|
context.commit('setPlaying', playerState)
|
|
|
|
},
|
|
|
|
setBuffering(context, bufferingState) {
|
|
|
|
context.commit('setBuffering', bufferingState)
|
|
|
|
},
|
|
|
|
setVolume(context, volume) {
|
|
|
|
context.commit('setVolume', volume)
|
|
|
|
},
|
2021-03-07 10:45:35 +00:00
|
|
|
loadVolume(context) {
|
|
|
|
const volume = localStorage.getItem('radio.volume')
|
|
|
|
if (typeof volume === 'string') {
|
|
|
|
context.commit('setVolume', volume)
|
|
|
|
}
|
|
|
|
},
|
2021-01-16 12:12:44 +00:00
|
|
|
toggleMute(context) {
|
|
|
|
context.commit('toggleMute')
|
|
|
|
},
|
|
|
|
togglePlay(context) {
|
|
|
|
context.commit('togglePlay')
|
|
|
|
},
|
|
|
|
setTitle(context, title) {
|
|
|
|
context.commit('setTitle', title)
|
|
|
|
},
|
2021-01-18 13:51:53 +00:00
|
|
|
playStation(context, station) {
|
2021-01-19 21:34:48 +00:00
|
|
|
context.commit('setBuffering', true)
|
|
|
|
context.commit('setTitle', station.name)
|
|
|
|
context.commit('setPausing', false)
|
2021-01-20 10:40:05 +00:00
|
|
|
player.doPlay(station.url_resolved || station.urlresolved)
|
2021-01-18 13:51:53 +00:00
|
|
|
},
|
|
|
|
|
2021-01-16 12:12:44 +00:00
|
|
|
},
|
|
|
|
})
|