Skip to content

Commit 58935b4

Browse files
author
Duke
committed
add basic autoplay config, closes #131
1 parent 583cda6 commit 58935b4

File tree

5 files changed

+67
-7
lines changed

5 files changed

+67
-7
lines changed

app/components/the-player.js

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export default Ember.Component.extend({
66
classNameBindings: ['hasModel'],
77
hasModel: Ember.computed.bool('controller.player.current'),
88

9+
autoplay: Ember.computed.alias('controller.player.autoplay'),
10+
911
episode: Ember.computed.alias('player.current'),
1012

1113
actions: {

app/services/player.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export default Ember.Service.extend({
77
current: null,
88
media: null,
99

10+
autoplay: true,
11+
1012
PLAYED_PERCENT: 95,
1113

1214
playpause(episode) {
@@ -44,13 +46,17 @@ export default Ember.Service.extend({
4446
},
4547

4648
_ended() {
47-
let episodesElements = Ember.$('li.episode').get().reverse();
48-
for (let i = 0; i <= episodesElements.length; i++) {
49-
let episodeElement = Ember.$(episodesElements[i]);
50-
if (!(episodeElement.is('.is-playing') || episodeElement.is('.is-played'))) {
51-
episodeElement.find('.playpause').click();
52-
break;
49+
if (this.get('autoplay')) {
50+
let episodesElements = Ember.$('li.episode').get().reverse();
51+
for (let i = 0; i <= episodesElements.length; i++) {
52+
let episodeElement = Ember.$(episodesElements[i]);
53+
if (!(episodeElement.is('.is-playing') || episodeElement.is('.is-played'))) {
54+
episodeElement.find('.playpause').click();
55+
break;
56+
}
5357
}
58+
} else {
59+
this.stop();
5460
}
5561
},
5662

@@ -74,6 +80,7 @@ export default Ember.Service.extend({
7480
_isTimeToPing(currentTime) {
7581
return currentTime % 5 === 0;
7682
},
83+
7784
_isPlayed(media) {
7885
let played = 100 * media.currentTime / media.duration;
7986
return played >= this.PLAYED_PERCENT;

app/styles/_player.sass

+22
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,28 @@
2828
padding: 5px
2929
width: 35%
3030

31+
label[for='autoplay']
32+
padding: 0
33+
position: relative
34+
display: block
35+
margin: 35px 15px
36+
p
37+
font-size: 10px
38+
margin: 0
39+
40+
#autoplay
41+
margin: 0
42+
position: absolute
43+
display: flex
44+
+ i
45+
background: #FFF
46+
border-radius: 0
47+
font-size: 24px
48+
49+
&:checked + i
50+
color: rgb(255, 87, 34)
51+
font-weight: bold
52+
3153
h2, h3
3254
padding: 0
3355
margin: 0px

app/templates/components/the-player.hbs

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
<h3 class="channel-title">{{episode.channel.title}}</h3>
66
</div>
77

8+
<label class="mdl-icon-toggle mdl-js-icon-toggle mdl-js-ripple-effect" for="autoplay">
9+
{{input checked=autoplay type="checkbox" class="mdl-icon-toggle__input" id="autoplay"}}
10+
<i class="mdl-icon-toggle__label material-icons">text_format</i>
11+
<p>autoplay</p>
12+
</label>
813

914
<button {{action "playpause" episode}} class="playpause material-icons">
1015
{{if episode.playing 'pause' 'play_arrow'}}
1116
</button>
1217

13-
<div id="wrapper-audio-element" class="player-audio-element">
18+
<div id="wrapper-audio-element" class="player-audio-element">
1419
<audio controls width="100%" class="audio-element"></audio>
1520
</div>
1621
</div>

tests/acceptance/player-test.js

+24
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,27 @@ test('player | when ended a episode should starts the next', function(assert) {
9090
assert.equal(find('#player .title').text(), episodes[i].title);
9191
});
9292
});
93+
94+
test('player | when ended a episode should not starts the next with autoplay off', function(assert) {
95+
const player = application.registry.container().lookup('service:player');
96+
player.set('autoplay', false);
97+
98+
visit(`/channels/${channel.id}`);
99+
100+
andThen(function() {
101+
assert.equal(currentURL(), `/channels/${channel.id}`);
102+
click('.episode:last .playpause');
103+
});
104+
105+
andThen(function() {
106+
let i = episodes.length - 1;
107+
assert.equal(find('#player .title').text(), episodes[i].title);
108+
$('.episode:last').addClass('is-played');
109+
player.successMedia(mediaMock('ended'));
110+
});
111+
112+
andThen(function() {
113+
let i = episodes.length - 1;
114+
assert.equal(find('#player .title').text(), episodes[i].title);
115+
});
116+
});

0 commit comments

Comments
 (0)