Skip to content

Commit 28d95a9

Browse files
committed
Fix: tutuktuk
1 parent 26d29e7 commit 28d95a9

5 files changed

Lines changed: 30 additions & 39 deletions

File tree

app/contexts/remote/provider.native.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const transfer = async (fromDevice, toDevice, config, song, songDispatch) => {
2525
const transferSameType = async (fromDevice, toDevice, config, song, songDispatch) => {
2626
// Save state from previous player
2727
const savedState = await Player.saveState()
28-
await Player.stopSong()
2928
await Player.disconnect(fromDevice)
3029

3130
// Connect to new player

app/services/servicePlayback.js

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,40 +52,37 @@ module.exports = async () => {
5252
})
5353
TrackPlayer.addEventListener(Event.PlaybackQueueEnded, (_event) => {
5454
if (!global.song?.queue?.length) return
55+
if (global.song?.songInfo?.id === 'tuktuktuk') return Player.resetAudio(global.songDispatch)
5556
getApi(global.config, 'scrobble', { id: global.song.songInfo.id, submission: true })
5657
.catch(() => { })
5758
if (global.song.actionEndOfSong === 'repeat') {
58-
TrackPlayer.seekTo(0)
59-
TrackPlayer.play()
59+
Player.setPosition(0)
60+
Player.resumeSong()
6061
} else if (!global.repeatQueue && global.song.index === global.song.queue.length - 1) {
61-
TrackPlayer.stop()
62+
Player.stopSong()
6263
} else Player.nextSong(global.config, global.song, fakeSongDispatch)
6364
})
6465
TrackPlayer.addEventListener(Event.PlaybackActiveTrackChanged, async (event) => {
65-
if (event.track?.id === 'tuktuktukend') {
66-
await TrackPlayer.remove([0, 1])
67-
} else {
68-
if (!lockDownload) {
69-
lockDownload = true
70-
downloadNextSong(global.song.queue, global.song.index)
71-
.then(() => {
72-
lockDownload = false
73-
})
74-
.catch((error) => {
75-
lockDownload = false
76-
logger.error('downloadNextSong', error)
77-
})
78-
}
66+
if (!lockDownload) {
67+
lockDownload = true
68+
downloadNextSong(global.song.queue, global.song.index)
69+
.then(() => {
70+
lockDownload = false
71+
})
72+
.catch((error) => {
73+
lockDownload = false
74+
logger.error('downloadNextSong', error)
75+
})
76+
}
7977

80-
if (event.track) {
81-
const now = Date.now()
82-
if (lastScrobble.id !== event.track.id || now - lastScrobble.time > 10 * 1000) {
83-
getApi(global.config, 'scrobble', { id: event.track.id, submission: false })
84-
.catch(() => { })
85-
lastScrobble = {
86-
id: event.track.id,
87-
time: now,
88-
}
78+
if (event.track) {
79+
const now = Date.now()
80+
if (lastScrobble.id !== event.track.id || now - lastScrobble.time > 10 * 1000) {
81+
getApi(global.config, 'scrobble', { id: event.track.id, submission: false })
82+
.catch(() => { })
83+
lastScrobble = {
84+
id: event.track.id,
85+
time: now,
8986
}
9087
}
9188
}

app/utils/player/playerCast.native.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ const connect = async (device) => {
227227
}
228228

229229
const disconnect = async (_device) => {
230+
await stopSong()
230231
const sessionManager = GoogleCast.getSessionManager()
231232
await sessionManager.endCurrentSession(true)
232233
}

app/utils/player/playerLocal.native.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const convertState = (state) => {
2424
}
2525

2626
const initPlayer = async (songDispatch) => {
27+
global.songDispatch = songDispatch
2728
const song = await AsyncStorage.getItem('song')
2829
.then((song) => song ? JSON.parse(song) : null)
2930
try {
@@ -202,7 +203,7 @@ const tuktuktuk = async (songDispatch) => {
202203
const urlTuk = 'https://sawyerf.github.io/tuktuktuk.mp3'
203204
const playingState = await TrackPlayer.getPlaybackState()
204205

205-
if ([State.Paused, State.Ended, State.Stopped, State.None].indexOf(playingState.state) > -1) {
206+
if ([State.Paused, State.Ended, State.Stopped, State.None, State.Error].indexOf(playingState.state) > -1) {
206207
const queue = [{
207208
id: 'tuktuktuk',
208209
albumId: 'tuktuktuk',
@@ -211,19 +212,10 @@ const tuktuktuk = async (songDispatch) => {
211212
album: 'Tuk Tuk Tuk',
212213
artist: 'Sawyerf',
213214
artwork: require('~/../assets/icon.png')
214-
},
215-
{
216-
id: 'tuktuktukend',
217-
albumId: 'tuktuktuk',
218-
url: urlTuk,
219-
title: 'Tuk Tuk Tuk',
220-
artist: 'Sawyerf',
221-
artwork: require('~/../assets/foreground-icon.png')
222215
}]
223-
await TrackPlayer.setQueue(queue)
224-
await TrackPlayer.play()
225216
songDispatch({ type: 'setQueue', queue, index: 0 })
226217
songDispatch({ type: 'setActionEndOfSong', action: 'next' })
218+
await loadSong(global.config, queue, 0)
227219
}
228220
}
229221

@@ -255,6 +247,7 @@ const connect = async (_device) => {
255247
}
256248

257249
const disconnect = async (_device) => {
250+
await stopSong()
258251
isConnected = false
259252
}
260253

app/utils/url.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ const realCover = (config, id, size = null) => {
1313

1414
export const urlCover = (config, id, size = null) => {
1515
if (!id) return null
16-
if (id === 'tuktuktuk') return 'https://github.com/sawyerf/Castafiore/blob/main/assets/icon.png?raw=true'
1716
if (!config?.url || !config?.query) return null
1817
if (typeof id === 'object') {
1918
const item = id
2019

20+
if (item.id === 'tuktuktuk') return 'https://github.com/sawyerf/Castafiore/blob/main/assets/icon.png?raw=true'
2121
if (item.homePageUrl && item.homePageUrl.startsWith('http')) {
2222
return item.homePageUrl + '/favicon.ico'
2323
}
@@ -38,6 +38,7 @@ export const urlCover = (config, id, size = null) => {
3838
}
3939

4040
export const urlStream = (config, id, format = 'raw', maxBitRate = 0) => {
41+
if (id === 'tuktuktuk') return 'https://sawyerf.github.io/tuktuktuk.mp3'
4142
if (!id.match(/^[a-zA-Z0-9-]*$/)) return id
4243
if (format === 'raw') return getUrl(config, 'stream', { id })
4344
return getUrl(config, 'stream', { id, format, maxBitRate })

0 commit comments

Comments
 (0)