2016-08-10 23:50:23 +02:00
|
|
|
// NPM imports
|
2016-08-04 15:28:07 +02:00
|
|
|
import React, { Component, PropTypes } from "react";
|
|
|
|
import CSSModules from "react-css-modules";
|
2016-08-05 00:00:25 +02:00
|
|
|
import { defineMessages, injectIntl, intlShape, FormattedMessage } from "react-intl";
|
2016-08-06 15:30:03 +02:00
|
|
|
import Immutable from "immutable";
|
2016-08-10 23:50:23 +02:00
|
|
|
import FontAwesome from "react-fontawesome";
|
2016-08-05 00:00:25 +02:00
|
|
|
|
2016-08-10 23:50:23 +02:00
|
|
|
// Local imports
|
2016-08-05 00:00:25 +02:00
|
|
|
import { messagesMap } from "../../utils";
|
2016-08-04 15:28:07 +02:00
|
|
|
|
2016-08-10 23:50:23 +02:00
|
|
|
// Styles
|
2016-08-04 15:28:07 +02:00
|
|
|
import css from "../../styles/elements/WebPlayer.scss";
|
|
|
|
|
2016-08-10 23:50:23 +02:00
|
|
|
// Translations
|
2016-08-05 00:00:25 +02:00
|
|
|
import commonMessages from "../../locales/messagesDescriptors/common";
|
|
|
|
import messages from "../../locales/messagesDescriptors/elements/WebPlayer";
|
|
|
|
|
2016-08-10 23:50:23 +02:00
|
|
|
// Define translations
|
2016-08-05 00:00:25 +02:00
|
|
|
const webplayerMessages = defineMessages(messagesMap(Array.concat([], commonMessages, messages)));
|
|
|
|
|
2016-08-10 23:50:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Webplayer component.
|
|
|
|
*/
|
2016-08-05 00:00:25 +02:00
|
|
|
class WebPlayerCSSIntl extends Component {
|
2016-08-10 23:50:23 +02:00
|
|
|
constructor(props) {
|
2016-08-05 00:00:25 +02:00
|
|
|
super(props);
|
|
|
|
|
2016-08-10 23:50:23 +02:00
|
|
|
// Bind this
|
2016-08-05 00:00:25 +02:00
|
|
|
this.artOpacityHandler = this.artOpacityHandler.bind(this);
|
2016-08-04 15:28:07 +02:00
|
|
|
}
|
|
|
|
|
2016-08-10 23:50:23 +02:00
|
|
|
/**
|
|
|
|
* Handle opacity on album art.
|
|
|
|
*
|
|
|
|
* Set opacity on mouseover / mouseout.
|
|
|
|
*
|
|
|
|
* @param ev A JS event.
|
|
|
|
*/
|
|
|
|
artOpacityHandler(ev) {
|
2016-08-05 00:00:25 +02:00
|
|
|
if (ev.type == "mouseover") {
|
2016-08-10 23:50:23 +02:00
|
|
|
// On mouse over, reduce opacity
|
2016-08-05 00:00:25 +02:00
|
|
|
this.refs.art.style.opacity = "1";
|
2016-08-07 00:58:36 +02:00
|
|
|
this.refs.artText.style.display = "none";
|
2016-08-05 00:00:25 +02:00
|
|
|
} else {
|
2016-08-10 23:50:23 +02:00
|
|
|
// On mouse out, set opacity back
|
2016-08-05 00:00:25 +02:00
|
|
|
this.refs.art.style.opacity = "0.75";
|
2016-08-07 00:58:36 +02:00
|
|
|
this.refs.artText.style.display = "block";
|
2016-08-05 00:00:25 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-04 15:28:07 +02:00
|
|
|
|
2016-08-10 23:50:23 +02:00
|
|
|
render() {
|
2016-08-05 00:00:25 +02:00
|
|
|
const { formatMessage } = this.props.intl;
|
2016-08-04 15:28:07 +02:00
|
|
|
|
2016-08-10 23:50:23 +02:00
|
|
|
// Get current song (eventually undefined)
|
|
|
|
const song = this.props.currentSong;
|
2016-08-07 00:58:36 +02:00
|
|
|
|
2016-08-10 23:50:23 +02:00
|
|
|
// Current status (play or pause) for localization
|
2016-08-05 00:00:25 +02:00
|
|
|
const playPause = this.props.isPlaying ? "pause" : "play";
|
2016-08-10 23:50:23 +02:00
|
|
|
// Volume fontawesome icon
|
|
|
|
const volumeIcon = this.props.isMute ? "volume-off" : "volume-up";
|
2016-08-07 00:58:36 +02:00
|
|
|
|
2016-08-10 23:50:23 +02:00
|
|
|
// Get classes for random and repeat buttons
|
2016-08-05 00:00:25 +02:00
|
|
|
const randomBtnStyles = ["randomBtn"];
|
|
|
|
const repeatBtnStyles = ["repeatBtn"];
|
|
|
|
if (this.props.isRandom) {
|
|
|
|
randomBtnStyles.push("active");
|
|
|
|
}
|
|
|
|
if (this.props.isRepeat) {
|
|
|
|
repeatBtnStyles.push("active");
|
|
|
|
}
|
2016-08-04 15:28:07 +02:00
|
|
|
|
2016-08-10 23:50:23 +02:00
|
|
|
// Check if a song is currently playing
|
|
|
|
let art = null;
|
|
|
|
let songTitle = null;
|
|
|
|
let artistName = null;
|
|
|
|
if (song) {
|
|
|
|
art = song.get("art");
|
|
|
|
songTitle = song.get("title");
|
|
|
|
if (this.props.currentArtist) {
|
|
|
|
artistName = this.props.currentArtist.get("name");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-11 22:01:47 +02:00
|
|
|
// Click handlers
|
|
|
|
const onPrev = (function () {
|
|
|
|
$(this.refs.prevBtn).blur();
|
|
|
|
this.props.onPrev();
|
|
|
|
}).bind(this);
|
|
|
|
const onPlayPause = (function () {
|
|
|
|
$(this.refs.playPauseBtn).blur();
|
|
|
|
this.props.onPlayPause();
|
|
|
|
}).bind(this);
|
|
|
|
const onSkip = (function () {
|
|
|
|
$(this.refs.nextBtn).blur();
|
|
|
|
this.props.onSkip();
|
|
|
|
}).bind(this);
|
|
|
|
const onMute = (function () {
|
|
|
|
$(this.refs.volumeBtn).blur();
|
|
|
|
this.props.onMute();
|
|
|
|
}).bind(this);
|
|
|
|
const onRepeat = (function () {
|
|
|
|
$(this.refs.repeatBtn).blur();
|
|
|
|
this.props.onRepeat();
|
|
|
|
}).bind(this);
|
|
|
|
const onRandom = (function () {
|
|
|
|
$(this.refs.randomBtn).blur();
|
|
|
|
this.props.onRandom();
|
|
|
|
}).bind(this);
|
|
|
|
|
2016-08-05 00:00:25 +02:00
|
|
|
return (
|
|
|
|
<div id="row" styleName="webplayer">
|
|
|
|
<div className="col-xs-12">
|
|
|
|
<div className="row" styleName="artRow" onMouseOver={this.artOpacityHandler} onMouseOut={this.artOpacityHandler}>
|
|
|
|
<div className="col-xs-12">
|
2016-08-10 23:50:23 +02:00
|
|
|
<img src={art} width="200" height="200" alt={formatMessage(webplayerMessages["app.common.art"])} ref="art" styleName="art" />
|
2016-08-07 00:58:36 +02:00
|
|
|
<div ref="artText">
|
2016-08-11 19:33:05 +02:00
|
|
|
{
|
|
|
|
(artistName && songTitle)
|
|
|
|
? (
|
|
|
|
<div>
|
|
|
|
<h2>{songTitle}</h2>
|
|
|
|
<h3>
|
|
|
|
<span className="text-capitalize">
|
|
|
|
<FormattedMessage {...webplayerMessages["app.webplayer.by"]} />
|
|
|
|
</span> { artistName }
|
|
|
|
</h3>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
: null
|
|
|
|
}
|
2016-08-07 00:58:36 +02:00
|
|
|
</div>
|
2016-08-05 00:00:25 +02:00
|
|
|
</div>
|
2016-08-04 15:28:07 +02:00
|
|
|
</div>
|
|
|
|
|
2016-08-05 00:00:25 +02:00
|
|
|
<div className="row text-center" styleName="controls">
|
|
|
|
<div className="col-xs-12">
|
2016-08-11 22:01:47 +02:00
|
|
|
<button styleName="prevBtn" aria-label={formatMessage(webplayerMessages["app.webplayer.previous"])} title={formatMessage(webplayerMessages["app.webplayer.previous"])} onClick={onPrev} ref="prevBtn">
|
2016-08-05 00:00:25 +02:00
|
|
|
<FontAwesome name="step-backward" />
|
|
|
|
</button>
|
2016-08-11 22:01:47 +02:00
|
|
|
<button className="play" styleName="playPauseBtn" aria-label={formatMessage(webplayerMessages["app.common." + playPause])} title={formatMessage(webplayerMessages["app.common." + playPause])} onClick={onPlayPause.bind(this)} ref="playPauseBtn">
|
2016-08-05 00:00:25 +02:00
|
|
|
<FontAwesome name={playPause} />
|
|
|
|
</button>
|
2016-08-11 22:01:47 +02:00
|
|
|
<button styleName="nextBtn" aria-label={formatMessage(webplayerMessages["app.webplayer.next"])} title={formatMessage(webplayerMessages["app.webplayer.next"])} onClick={onSkip} ref="nextBtn">
|
2016-08-05 00:00:25 +02:00
|
|
|
<FontAwesome name="step-forward" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div className="col-xs-12">
|
2016-08-11 22:01:47 +02:00
|
|
|
<button styleName="volumeBtn" aria-label={formatMessage(webplayerMessages["app.webplayer.volume"])} title={formatMessage(webplayerMessages["app.webplayer.volume"])} onClick={onMute} ref="volumeBtn">
|
2016-08-10 23:50:23 +02:00
|
|
|
<FontAwesome name={volumeIcon} />
|
2016-08-05 00:00:25 +02:00
|
|
|
</button>
|
2016-08-11 22:01:47 +02:00
|
|
|
<button styleName={repeatBtnStyles.join(" ")} aria-label={formatMessage(webplayerMessages["app.webplayer.repeat"])} title={formatMessage(webplayerMessages["app.webplayer.repeat"])} aria-pressed={this.props.isRepeat} onClick={onRepeat} ref="repeatBtn">
|
2016-08-05 00:00:25 +02:00
|
|
|
<FontAwesome name="repeat" />
|
|
|
|
</button>
|
2016-08-11 22:01:47 +02:00
|
|
|
<button styleName={randomBtnStyles.join(" ")} aria-label={formatMessage(webplayerMessages["app.webplayer.random"])} title={formatMessage(webplayerMessages["app.webplayer.random"])} aria-pressed={this.props.isRandom} onClick={onRandom} ref="randomBtn">
|
2016-08-05 00:00:25 +02:00
|
|
|
<FontAwesome name="random" />
|
|
|
|
</button>
|
|
|
|
<button styleName="playlistBtn" aria-label={formatMessage(webplayerMessages["app.webplayer.playlist"])} title={formatMessage(webplayerMessages["app.webplayer.playlist"])}>
|
|
|
|
<FontAwesome name="list" />
|
|
|
|
</button>
|
|
|
|
</div>
|
2016-08-04 15:28:07 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-05 00:00:25 +02:00
|
|
|
WebPlayerCSSIntl.propTypes = {
|
|
|
|
isPlaying: PropTypes.bool.isRequired,
|
|
|
|
isRandom: PropTypes.bool.isRequired,
|
|
|
|
isRepeat: PropTypes.bool.isRequired,
|
2016-08-07 00:58:36 +02:00
|
|
|
isMute: PropTypes.bool.isRequired,
|
2016-08-10 23:50:23 +02:00
|
|
|
volume: PropTypes.number.isRequired,
|
|
|
|
currentIndex: PropTypes.number.isRequired,
|
|
|
|
playlist: PropTypes.instanceOf(Immutable.List).isRequired,
|
|
|
|
currentSong: PropTypes.instanceOf(Immutable.Map),
|
2016-08-07 00:58:36 +02:00
|
|
|
currentArtist: PropTypes.instanceOf(Immutable.Map),
|
|
|
|
onPlayPause: PropTypes.func.isRequired,
|
|
|
|
onPrev: PropTypes.func.isRequired,
|
|
|
|
onSkip: PropTypes.func.isRequired,
|
|
|
|
onRandom: PropTypes.func.isRequired,
|
|
|
|
onRepeat: PropTypes.func.isRequired,
|
|
|
|
onMute: PropTypes.func.isRequired,
|
2016-08-10 23:50:23 +02:00
|
|
|
intl: intlShape.isRequired,
|
2016-08-05 00:00:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default injectIntl(CSSModules(WebPlayerCSSIntl, css, { allowMultiple: true }));
|