Автообновление данных о треке в режиме трансляции
This commit is contained in:
parent
3f3086c141
commit
338a68d792
|
|
@ -64,10 +64,11 @@ export default {
|
|||
},
|
||||
watch: {},
|
||||
created() {
|
||||
this.$store.dispatch('setCurrentPlay', {
|
||||
...this.currentPlay,
|
||||
isPlay: false,
|
||||
});
|
||||
// Нахуя это здесь?
|
||||
// this.$store.dispatch('setCurrentPlay', {
|
||||
// ...this.currentPlay,
|
||||
// isPlay: false,
|
||||
// });
|
||||
},
|
||||
mounted() {},
|
||||
methods: {},
|
||||
|
|
|
|||
|
|
@ -174,7 +174,9 @@ export default {
|
|||
this.connectionPlayer();
|
||||
},
|
||||
mounted() {
|
||||
// Создание <audio>
|
||||
this.$store.dispatch('initPlayer', { volume: this.songVolume });
|
||||
|
||||
if (this.user?.id) {
|
||||
this.checkSongIsFavorite();
|
||||
this.getSongList();
|
||||
|
|
@ -210,7 +212,7 @@ export default {
|
|||
this.connection = new Player();
|
||||
this.connection.init();
|
||||
|
||||
this.connection.onHandler(this.handlePlayer);
|
||||
this.connection.onHandler(this.handleConnection);
|
||||
},
|
||||
checkSongIsFavorite() {
|
||||
app
|
||||
|
|
@ -233,7 +235,7 @@ export default {
|
|||
console.error(err);
|
||||
});
|
||||
},
|
||||
handlePlayer(e) {
|
||||
handleConnection(e) {
|
||||
// console.log('getPlaying', e);
|
||||
const jsonData = JSON.parse(e.data);
|
||||
// console.log('jsonData', jsonData);
|
||||
|
|
@ -243,30 +245,42 @@ export default {
|
|||
// Первый ответ
|
||||
jsonData?.connect?.subs?.['station:it-radio']?.publications?.[0]?.data;
|
||||
// console.log('getPlaying', data);
|
||||
console.log(data);
|
||||
|
||||
if (!data) return;
|
||||
if (this.currentPlay.live) {
|
||||
// Ссылка на трансляцию
|
||||
const dataUrl = data.np.station.listen_url;
|
||||
// Объект с данными музыки
|
||||
const dataSong = data.np.now_playing.song;
|
||||
console.log(dataSong);
|
||||
const playerUrl = this.player.target.src;
|
||||
if (dataUrl !== playerUrl) {
|
||||
// console.log('data.np.station.listen_url', dataUrl);
|
||||
this.$store.dispatch('changePlayer', dataUrl);
|
||||
// console.log(this.player);
|
||||
const currentPlay = {
|
||||
...this.currentPlay,
|
||||
// Инфа про текущий трек
|
||||
...data.np.now_playing.song,
|
||||
azura_id: data.np.now_playing.song.id,
|
||||
isLoader: false,
|
||||
live: true,
|
||||
currentIndex: null,
|
||||
};
|
||||
// console.log('params in getPlaying ', params);
|
||||
// delete params.unique_id;
|
||||
this.$store.dispatch('setCurrentPlay', currentPlay);
|
||||
this.actionCurrentPlay(dataSong);
|
||||
}
|
||||
if (dataSong.id !== this.currentPlay.id) {
|
||||
this.actionCurrentPlay(dataSong);
|
||||
}
|
||||
}
|
||||
},
|
||||
actionCurrentPlay(song) {
|
||||
// console.log('actionCurrentPlay', data);
|
||||
const currentPlay = {
|
||||
...this.currentPlay,
|
||||
// Инфа про текущий трек
|
||||
...song,
|
||||
// azura_id: song.id,
|
||||
isLoader: false,
|
||||
live: true,
|
||||
currentIndex: null,
|
||||
};
|
||||
// console.log('params in getPlaying ', params);
|
||||
// delete params.unique_id;
|
||||
this.$store.dispatch('setCurrentPlay', currentPlay);
|
||||
},
|
||||
updateProgress(e) {
|
||||
this.playerInfo = {
|
||||
...this.playerInfo,
|
||||
|
|
@ -290,8 +304,8 @@ export default {
|
|||
}
|
||||
},
|
||||
handlerPlay() {
|
||||
console.log(this.currentPlay);
|
||||
console.log(this.player);
|
||||
// console.log(this.currentPlay);
|
||||
// console.log(this.player);
|
||||
this.$store.dispatch('handlerPlayer', { play: true });
|
||||
},
|
||||
handlerPause() {
|
||||
|
|
@ -356,12 +370,12 @@ export default {
|
|||
toggleVolume() {
|
||||
if (this.songVolume === 0) {
|
||||
this.songVolume = this.preToggleVol;
|
||||
console.log(this.songVolume);
|
||||
// console.log(this.songVolume);
|
||||
this.$store.dispatch('handlerPlayer', { volume: this.songVolume });
|
||||
} else {
|
||||
this.preToggleVol = this.songVolume;
|
||||
this.songVolume = 0.0;
|
||||
console.log(this.songVolume);
|
||||
// console.log(this.songVolume);
|
||||
this.$store.dispatch('handlerPlayer', { volume: this.songVolume });
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ export default createStore({
|
|||
initPlayer(state, { volume }) {
|
||||
// console.log(params);
|
||||
state.player.target = document.createElement('audio');
|
||||
console.log(state.player.target);
|
||||
// console.log(state.player.target);
|
||||
state.player.target.src = '';
|
||||
state.player.target.preload = 'auto';
|
||||
state.player.target.controls = true;
|
||||
|
|
@ -90,13 +90,13 @@ export default createStore({
|
|||
state.player.target.addEventListener('canplaythrough', awaitPlay);
|
||||
},
|
||||
handlerPlayer(state, params) {
|
||||
console.log('hanlerPlayer', params);
|
||||
// console.log('hanlerPlayer', params);
|
||||
if (params.pause) {
|
||||
state.currentPlay.isPlay = false;
|
||||
state.player.target.pause();
|
||||
}
|
||||
if (params.play) {
|
||||
console.log(state);
|
||||
// console.log(state);
|
||||
if (state.player.target.readyState >= 3) {
|
||||
state.currentPlay.isPlay = true;
|
||||
state.player.target.play();
|
||||
|
|
|
|||
Loading…
Reference in New Issue