Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return async (dispatch, getState) => {
try {
dispatch(playbackState(await TrackPlayer.getState()));
dispatch(playbackTrack(await TrackPlayer.getCurrentTrack()));
} catch(e) {
// The player is probably not yet initialized
// which means we don't have to update anything
console.log(e);
}
};
}
async _updateProgress() {
try {
const data = {
position: await TrackPlayer.getPosition(),
bufferedPosition: await TrackPlayer.getBufferedPosition(),
duration: await TrackPlayer.getDuration(),
track: await TrackPlayer.getTrack(await TrackPlayer.getCurrentTrack()),
};
if (this._progressUpdates) {
this.setState(data);
}
} catch (e) {
// The player is probably not initialized yet, we'll just ignore it
}
}
_checkChangeSelectedTrack = async () => {
let isCurrentTrack;
isCurrentTrack = await !!TrackPlayer.getCurrentTrack().catch(() => {
// If nothing is playing, it rejects the promise
isCurrentTrack = false;
});
if (isCurrentTrack) {
this._playNewTrack();
}
};
.then(tracks => {
TrackPlayer.getCurrentTrack().then(currentTrackId => {
const currentItemIndex = utils.getIndexOfTrackUsingId(tracks, currentTrackId);
const tracksToLeft = this._getTracksToLeft(tracks, currentItemIndex, amountOfTracksToLeft);
trackCurrent = tracks[currentItemIndex];
const tracksToRight = this._getTracksToRight(tracks, currentItemIndex, amountOfTracksToRight);
[shouldFetchCurrent ? trackCurrent : {}, ...tracksToRight, ...tracksToLeft].map((item, index) => {
if (item.videoId && ytdl.validateID(item.videoId)) {
this._ytdlGetInfo(
item.videoId,
info => {
console.log(JSON.stringify(info));
const highestQualityAudio = this._filterHighestQualityAudio(info.formats);
this._updateTrackPlayerQueueItem(
tracks,
_getCurrentTrackId = callback => {
TrackPlayer.getCurrentTrack()
.then(trackid => {
callback(trackid);
})
.catch(e => console.error(e));
};
return async dispatch => {
const trackId = await TrackPlayer.getCurrentTrack()
const duration = await TrackPlayer.getDuration()
const track = await TrackPlayer.getTrack(trackId)
dispatch({
type: types.TRACK,
payload: {
track,
duration
}
})
}
}
const togglePlayback = async () => {
const currentTrack = await TrackPlayer.getCurrentTrack();
if(currentTrack){
if (playbackState === TrackPlayer.STATE_PAUSED) {
await TrackPlayer.play();
} else {
await TrackPlayer.pause();
}
}
};
async function togglePlayback() {
const currentTrack = await TrackPlayer.getCurrentTrack();
if (currentTrack == null) {
await TrackPlayer.reset();
await TrackPlayer.add(playlistData);
await TrackPlayer.add({
id: "local-track",
url: localTrack,
title: "Pure (Demo)",
artist: "David Chavez",
artwork: "https://picsum.photos/200"
});
await TrackPlayer.play();
} else {
if (playbackState === TrackPlayer.STATE_PAUSED) {
await TrackPlayer.play();
} else {
await TrackPlayer.pause();