Commit 38df7abb authored by fukino's avatar fukino Committed by Commit bot

AudioPlayer: Start playing a track when play icon on the track list is clicked.

Clicking a track usually changes tracks but doesn't change the play state. (play / pause)
With this CL, clicking play icon which is shown on hover will force start playing the track.

BUG=488229
TEST=manually

Review URL: https://codereview.chromium.org/1431523003

Cr-Commit-Position: refs/heads/master@{#357071}
parent 6cab7221
......@@ -15,7 +15,8 @@
expanded$="[[expanded]]"
shuffle="[[shuffle]]"
current-track-index="{{currentTrackIndex}}"
on-replay="onReplayCurrentTrack"></track-list>
on-replay="onReplayCurrentTrack"
on-play="onPlayCurrentTrack"></track-list>
<control-panel id="audioController"
playing="{{playing}}"
time="{{time}}"
......
......@@ -300,6 +300,13 @@ Polymer({
this.playing = !this.$.audio.paused;
},
/**
* Invoked when receivig a request to start playing the current music.
*/
onPlayCurrentTrack: function() {
this.$.audio.play();
},
/**
* Invoked when receiving a request to replay the current music from the track
* list element.
......
......@@ -46,6 +46,7 @@
flex: none;
height: 32px;
margin: 8px;
pointer-events: none;
width: 32px;
}
......@@ -53,6 +54,7 @@
background-image: -webkit-image-set(
url(../assets/100/playlist_play.png) 1x,
url(../assets/200/playlist_play.png) 2x);
pointer-events: auto;
}
.track[active] .icon {
......
......@@ -166,8 +166,15 @@ var TrackInfo;
trackClicked: function(event) {
var index = ~~event.currentTarget.getAttribute('index');
var track = this.tracks[index];
if (track)
this.selectTrack(track);
if (track) {
if (event.target.classList.contains('icon')) {
// If the play icon on the track is clicked, change the current track
// and start playing it regardless of current play state.
this.selectTrack(track, true /* force to play */);
} else {
this.selectTrack(track, false /* force to play */);
}
}
},
/**
......@@ -250,8 +257,10 @@ var TrackInfo;
* Sets the current track.
* @param {!TrackInfo} track TrackInfo to be set as the current
* track.
* @param {boolean} forcePlay True if the track should be played regardless
* of the current play state (paused/played).
*/
selectTrack: function(track) {
selectTrack: function(track, forcePlay) {
var index = -1;
for (var i = 0; i < this.tracks.length; i++) {
if (this.tracks[i].url === track.url) {
......@@ -261,10 +270,13 @@ var TrackInfo;
}
if (index >= 0) {
// TODO(yoshiki): Clean up the flow and the code around here.
if (this.currentTrackIndex == index)
if (this.currentTrackIndex === index) {
this.replayCurrentTrack();
else
} else {
this.currentTrackIndex = index;
if (forcePlay)
this.fire('play');
}
}
},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment