Skip to content

Commit

Permalink
minor fixes for audio being out of sync
Browse files Browse the repository at this point in the history
  • Loading branch information
sneljo1 committed Aug 28, 2018
1 parent b03511e commit 23f73e0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 48 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Expand Up @@ -73,9 +73,9 @@ after_success:
if [ "$TRAVIS_BRANCH" == "master" ] || [ -n "$TRAVIS_TAG" ]; then
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
# Only create snap in when untagged, otherwise snaps build service will do this for us
if [ -z $TRAVIS_TAG ]; then
sed -i "s/\"AppImage\",/\"AppImage\",\"snap\",/g" package.json
fi
# if [ -z $TRAVIS_TAG ]; then
# sed -i "s/\"AppImage\",/\"AppImage\",\"snap\",/g" package.json
# fi
yarn run release:linux
else
yarn run release:mac
Expand Down
4 changes: 2 additions & 2 deletions scripts/deploy.sh
Expand Up @@ -30,8 +30,8 @@ cd ..
if ! [[ -z $3 ]]; then
git clone ssh://aur@aur.archlinux.org/auryo-bin.git AUR-repo
cd AUR-repo
sed -i "s/[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+)?/$PACKAGE_VERSION/g" PKGBUILD
sed -i "s/[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+)?/$PACKAGE_VERSION/g" .SRCINFO
perl -pi -e "s/[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+)?/$PACKAGE_VERSION/g" PKGBUILD
perl -pi -e "s/[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+)?/$PACKAGE_VERSION/g" .SRCINFO
git add -A
git commit --message "Travis build $2 for ${PACKAGE_VERSION}"
git push --quiet --set-upstream origin master
Expand Down
4 changes: 2 additions & 2 deletions src/main/features/linux/MprisService.js
Expand Up @@ -126,9 +126,9 @@ export default class MprisService extends ILinuxFeature {
this.meta['xesam:genre'] = track.genre || ''
this.meta['xesam:contentCreated'] = track.created_at || 'Unknown release date'
} else {
this.meta['mpris:trackid'] = "track.id"
this.meta['xesam:title'] = "Auryo"
this.meta['xesam:artist'] = "[user && user.username ? user.username : 'Unknown artist']"
this.meta['xesam:artist'] = ""
this.meta['xesam:url'] = ""
this.meta['mpris:artUrl'] = `file://${path.join(logosPath, 'auryo-128.png')}`
}

Expand Down
86 changes: 45 additions & 41 deletions src/renderer/modules/player/components/audio/Audio.jsx
Expand Up @@ -3,20 +3,27 @@
import throttle from 'lodash/throttle';
import PropTypes from 'prop-types';
import { Component } from 'react';
import { toastr } from "react-redux-toastr";
import { PLAYER_STATUS } from '../../../../../shared/constants/index';

class Audio extends Component {

constructor() {
super()
constructor(props) {
super(props)

// html audio element used for playback
this.player = null

this.throttleUpdateTimeFunc = throttle(() => {
if (this.player) {
props.onPlaying(this.player.currentTime())
}
}, 500, { trailing: false })
}

componentDidMount() {
const { url } = this.props;
this.startStream(url)
const { url, playStatus } = this.props;
this.startStream(url, playStatus)
this._isMounted = true
}

Expand All @@ -26,25 +33,29 @@ class Audio extends Component {
if (playFromPosition !== nextProps.playFromPosition && nextProps.playFromPosition !== -1 && this.player) {
this.player.seek(nextProps.playFromPosition)
onTimeUpdate()
console.log("1")
}

if (url !== nextProps.url || id !== nextProps.id) {
this.startStream(nextProps.url)
this.startStream(nextProps.url, nextProps.playStatus)
console.log("2")
} else if (playStatus !== nextProps.playStatus) {
this.toggleStatus(nextProps.playStatus)
console.log("3")
}

if (this.player && this.player.getState() === 'playing' && !this.player.isActuallyPlaying()) {
this.player.play()
console.log("4")
} else if (!this.player) {
this.startStream(nextProps.url)
this.startStream(nextProps.url, nextProps.playStatus)
console.log("5")
}

if (volume !== nextProps.volume && this.player) {
this.player.setVolume(nextProps.volume)
}
if (muted !== nextProps.muted && this.player) {
this.player.setVolume(nextProps.muted ? 0 : nextProps.volume)
} else if (volume !== nextProps.volume && this.player) {
this.player.setVolume(nextProps.volume)
}

}
Expand All @@ -67,59 +78,45 @@ class Audio extends Component {
}
}

startStream = (url) => {
if (this.player) {
this.player.pause()
}

if (url) {
this.setState({
loading: true
})
startStream = (url, playStatus) => {
const { volume } = this.props;

SC.stream(url)
if (url)
SC.stream(url) // eslint-disable-line
.then((player) => {

if (!this._isMounted) return

this.setState({
loading: false
})

this.player = player

if (this.props.playStatus === PLAYER_STATUS.PLAYING) {
if (playStatus === PLAYER_STATUS.PLAYING && !player.isPlaying()) {
this.play()
}

this.setListeners()

this.player.setVolume(this.props.volume)
this.player.setVolume(volume)
})
.catch((e) => {
console.error(e)
})
}

}

setListeners = () => {
let updateTime = () => {
this.props.onPlaying(this.player.currentTime())
}

const throttleUpdateTimeFunc = throttle(updateTime, 500, { trailing: false })
const { onFinishedPlaying, onLoading } = this.props;

if (this.player) {
this.player.on('finish', this.props.onFinishedPlaying)
this.player.on('finish', onFinishedPlaying)
this.player.on('play-start', () => {
if (this.player) {
this.props.onLoading(this.player.getDuration())
onLoading(this.player.getDuration())
}
})
this.player.on('time', throttleUpdateTimeFunc)
this.player.on('time', this.throttleUpdateTimeFunc)

this.player.on('audio_error', (e) => {
console.log("audio_error", e)
toastr.error('Something went wrong playing this song');
})

}
Expand All @@ -128,30 +125,33 @@ class Audio extends Component {
play = () => {
if (this.player) {
this.player.play()
.then(() => {
const { playStatus } = this.props;

if (playStatus === PLAYER_STATUS.PAUSED && this.player.getState() === 'playing') {
this.player.pause()
}
})
.catch((e) => {
console.error('Playback rejected.', e)

this.play()
})
}
}

toggleStatus(value) {

toggleStatus = (value) => {
if (!this.player) {
return
}

if (!this.player.isPlaying() && value === PLAYER_STATUS.PLAYING) {
this.play(this.audio)
this.play()
} else if (this.player.isPlaying() && value === PLAYER_STATUS.PAUSED) {
this.player.pause()
} else if (value === PLAYER_STATUS.STOPPED) {
this.player.pause()
this.player.seek(0)
}


}

render() {
Expand All @@ -174,4 +174,8 @@ Audio.propTypes = {
onTimeUpdate: PropTypes.func.isRequired,
}

Audio.defaultProps = {
playStatus: PLAYER_STATUS.STOPPED
}

export default Audio

0 comments on commit 23f73e0

Please sign in to comment.