import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import Link from './Link'
import { bindActionCreators } from 'redux'
import ProgressSlider from './Fields/ProgressSlider'
import VolumeControl from './Fields/VolumeControl'
import MuteControl from './Fields/MuteControl'
import OutputControl from './Fields/OutputControl'
import Dater from './Dater'
import ArtistSentence from './ArtistSentence'
import Thumbnail from './Thumbnail'
import Icon from './Icon'
import * as helpers from '../helpers'
import * as uiActions from '../services/ui/actions'
import * as coreActions from '../services/core/actions'
import * as mopidyActions from '../services/mopidy/actions'
class PlaybackControls extends React.Component{
constructor(props){
super(props)
this.stream = null;
this.state = {
expanded: false
}
}
componentDidMount(){
if (this.props.http_streaming_enabled){
// Bust our cache, and by consequence, play our stream
this.props.coreActions.cachebustHttpStream();
}
}
playStream(props = this.props){
if (!this.stream){
this.stream = new Audio();
} else {
this.stream.src = null;
}
if (!props.http_streaming_enabled || !props.http_streaming_url){
return false;
}
this.stream.src = props.http_streaming_url+"?cb="+props.http_streaming_cachebuster;
this.stream.muted = props.http_streaming_mute;
this.stream.volume = props.http_streaming_volume / 100;
this.stream.play();
console.log("Playing stream: "+this.stream.src);
}
componentWillReceiveProps(nextProps){
// Cachebuster changed
// This happens when playback changes, so that the stream is "new", rather
// than the original stream. This prevents the browser cache from starting
// the stream right from the beginning (which could be hours of continuous playback).
if (this.props.http_streaming_cachebuster !== nextProps.http_streaming_cachebuster){
this.playStream(nextProps);
}
// Just been enabled
if (!this.props.http_streaming_enabled && nextProps.http_streaming_enabled){
this.playStream(nextProps);
}
if (this.stream){
// Just been muted
if (this.props.http_streaming_mute !== nextProps.http_streaming_mute){
this.stream.muted = nextProps.http_streaming_mute;
}
// Just had volume changed
if (this.props.http_streaming_volume !== nextProps.http_streaming_volume){
this.stream.volume = nextProps.http_streaming_volume / 100;
}
// Just been disabled
if (!nextProps.http_streaming_enabled){
this.stream = null;
}
}
}
renderPlayButton(){
var button = this.props.mopidyActions.play()}>