# HG changeset patch # User nowmad@23.1.168.192.in-addr.arpa # Date 1453226777 -3600 # Node ID 15ded106ef1a44af1c44bdb3f111382d6ed9088a # Parent e95ca73cec549fdeb596e8ca0453aecbf27a329a add a player component to handle sound play/pause diff -r e95ca73cec54 -r 15ded106ef1a cms/app-client/app/components/player-component.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/app/components/player-component.js Tue Jan 19 19:06:17 2016 +0100 @@ -0,0 +1,115 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + classNames: ['player-component'], + currentTime: "00:00", + duration: "00:00", + + _soundChanged: Ember.observer('sound', function() { + this.pause(); + this.changeTime(0); + this.updateProgress(0); + this.audio.src = this.get("sound").get("master"); + this.audio.load(); + this.set("currentTime", "00:00"); + }), + + didInsertElement: function(){ + var _this = this; + + this.audio = new Audio("http://stop.com.pk/file/music_folder/700.mp3"); + + this.button = { + play: $('#action_play'), + progress: $('.progress') + }; + + $(document).on('touchmove', function(e){ + e.preventDefault(); + }); + + // seeker + this.button.progress.on('mousedown', function(e){ + var r = _this.rotation(e.pageX, e.pageY); + _this.updateProgress(r); + _this.changeTime(r/360*100); + }); + + this.audio.addEventListener('loadedmetadata',function (){ + var minutes = Math.floor( _this.audio.duration / 60); + var seconds = Math.floor(_this.audio.duration) % 60; + _this.set('duration', ('0' + minutes).slice(-2)+':'+('0' + seconds).slice(-2)); + }); + + // update bar onchange + this.audio.addEventListener('timeupdate',function (){ + var curtime = _this.audio.currentTime, + percent = (curtime/_this.audio.duration)*100, + rounded = Math.round(percent*1000)/1000, + deg = 360/100*percent, + minutes = Math.floor( curtime / 60), + seconds = Math.floor(curtime) % 60; + _this.set('currentTime', ('0' + minutes).slice(-2)+':'+('0' + seconds).slice(-2)); + _this.updateProgress(deg); + }); + + // when the audio has finished playing + this.audio.addEventListener('ended', function(){ + _this.pause(); + _this.changeTime(0); + _this.updateProgress(0); + }); + }, + // change seeked time + changeTime: function(percent){ + var t = (this.audio.duration*percent)/100; + this.audio.currentTime = t; + }, + updateProgress: function(deg){ + var $slice = $('.slice'); + + if (deg > 180 && !$slice.is('.gt50')) { + $slice.addClass('gt50'); + $slice.append('
'); + } else if (deg < 180 && $slice.is('.gt50')) { + $slice.removeClass('gt50'); + $slice.find('.fill').remove(); + } + + $slice.find('.pie').css({ + '-moz-transform':'rotate('+deg+'deg)', + '-webkit-transform':'rotate('+deg+'deg)', + '-o-transform':'rotate('+deg+'deg)', + 'transform':'rotate('+deg+'deg)' + }); + }, + rotation: function(x,y){ + var offset = this.button.progress.offset(); + var button_centerX = (offset.left) + (this.button.progress.width()/2); + var button_centerY = (offset.top) + (this.button.progress.height()/2); + + var radians = Math.atan2(x - button_centerX, y - button_centerY); + var degree = Math.round( (radians * (180 / Math.PI) * -1) + 180 ); + return degree; + //return (degree <= max ? degree : max); + }, + play: function(){ + this.audio.play(); + this.button.play.addClass('playing'); + this.button.play.text('Pause'); + }, + pause: function(){ + this.audio.pause(); + this.button.play.removeClass('playing'); + this.button.play.text('Play'); + }, + actions: { + tooglePlay: function(){ + if (this.button.play.is('.playing')) { + this.pause(); + } else { + this.play(); + } + } + } +}); diff -r e95ca73cec54 -r 15ded106ef1a cms/app-client/app/controllers/application.js --- a/cms/app-client/app/controllers/application.js Mon Jan 18 10:01:39 2016 +0100 +++ b/cms/app-client/app/controllers/application.js Tue Jan 19 19:06:17 2016 +0100 @@ -54,11 +54,11 @@ queryParams[query] = array || null; this.transitionToRoute({queryParams: queryParams}); }, - play: function(item){ - this.set("currentItem", item); - $("#audio-player").load(); - $(".result-item").toggleClass("playing", false); - $("#"+item.id).toggleClass("playing", true); + previous: function(){ + console.log("previous"); + }, + next: function(){ + console.log("next"); }, details: function(item){ if ($("#"+item.id).hasClass("details")){ diff -r e95ca73cec54 -r 15ded106ef1a cms/app-client/app/controllers/player.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/app/controllers/player.js Tue Jan 19 19:06:17 2016 +0100 @@ -0,0 +1,76 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ + queryParams: ['location', 'langue', 'discours', 'date', 'thematique'], + location: null, + langue: null, + discours: null, + date: [], + thematique: null, + isShowingModal: false, + currentDetails: null, + currentItem: {title: "example", master: 'http://www.noiseaddicts.com/samples_1w72b820/3921.mp3'}, + filteredSounds: Ember.computed('location', 'langue', 'discours', 'date', 'thematique', 'model', function() { + var location = this.get('location'); + var langue = this.get('langue'); + var discours = this.get('discours'); + var date = this.get('date'); + var thematique = this.get('thematique'); + + var sounds = this.get('model'); + + if (location) { + sounds = sounds.filterBy('spatial', location); + } + if (langue) { + sounds = sounds.filterBy('language', langue); + } + if (discours) { + sounds = sounds.filterBy('type', discours); + } + if (date.length > 0) { + var temp = sounds; + sounds.map(function(elt, index){ + if (date.indexOf(elt.get('created')) === -1){ + temp = temp.without(elt); + } + }); + sounds = temp; + } + if (thematique) { + sounds = sounds.filterBy('thematique', thematique); + } + return sounds; + }), + actions: { + deleteTag: function(query, item){ + var queryParams = {}; + if (query === 'date'){ + var array = this.get('date'); + if(array.indexOf(item) !== -1) { + array.splice(array.indexOf(item), 1); + } + } + queryParams[query] = array || null; + this.transitionToRoute({queryParams: queryParams}); + }, + previous: function(){ + console.log("previous"); + }, + next: function(){ + console.log("next"); + }, + details: function(item){ + if ($("#"+item.id).hasClass("details")){ + $("#"+item.id).toggleClass("details", false); + } else{ + $(".result-item").toggleClass("details", false); + $("#"+item.id).toggleClass("details", true); + } + }, + toggleModal: function(item){ + this.set("isShowingModal", !this.isShowingModal); + this.set("currentDetails", item); + } + } +}); diff -r e95ca73cec54 -r 15ded106ef1a cms/app-client/app/styles/player.scss --- a/cms/app-client/app/styles/player.scss Mon Jan 18 10:01:39 2016 +0100 +++ b/cms/app-client/app/styles/player.scss Tue Jan 19 19:06:17 2016 +0100 @@ -1,4 +1,93 @@ -#audio-player{ +.player-component{ + text-align: center; +} + +#audio_player { + display: inline-block; + width: 80px; + height: 80px; + position: relative; + padding: 8px; + margin: 10px auto; + background: #fff; + border-radius: 88px; +} +#audio_player .background { + width: 60px; + height: 60px; + border: solid 10px #e5e5e5; + background: #fff; + border-radius: 80px; +} +#audio_player .btn { + cursor: pointer; +} +#audio_player .btn_play { display: block; - margin: 10px auto; + width: 32px; + height: 32px; + position: absolute; + top: 50%; + left: 50%; + margin-top: -16px; + margin-left: -16px; + text-indent: -900em; + z-index: 10; + background: url(images/button_play.png) 10px no-repeat; + background-size: 21px 31px; +} +/* pause */ +#audio_player .btn_play.playing { + background: url(images/button_pause.png) center no-repeat; + background-size: 28px 28px; +} +#audio_player .progress { + position: absolute; + width: 80px; + height: 80px; + top: 8px; + left: 8px; +} +#audio_player .progress .slice { + position: absolute; + width: 80px; + height: 80px; + clip: rect(0px,80px,80px,40px); +} +#audio_player .progress .slice.gt50 { + clip: rect(auto, auto, auto, auto); } +#audio_player .progress .slice .pie { + border: 10px solid #276f84; + position: absolute; + width: 60px; + height: 60px; + clip: rect(0,40px,80px,0); + -moz-border-radius: 80px; + -webkit-border-radius: 80px; + border-radius: 80px; +} +#audio_player .progress .slice .pie.fill { + -moz-transform: rotate(180deg) !important; + -webkit-transform: rotate(180deg) !important; + -o-transform: rotate(180deg) !important; + transform: rotate(180deg) !important; +} + +.audio-controls { + color: #2a768c; + cursor: pointer; + display: inline-block; + font-size: 30px; + margin: 43px 10px; + vertical-align: top; +} + +.duration{ + margin: -5px auto; + text-align: center; +} + +.audio-wrapper{ + display: inline-block; +} diff -r e95ca73cec54 -r 15ded106ef1a cms/app-client/app/templates/components/player-component.hbs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cms/app-client/app/templates/components/player-component.hbs Tue Jan 19 19:06:17 2016 +0100 @@ -0,0 +1,17 @@ ++ {{currentTime}} / {{duration}} +
diff -r e95ca73cec54 -r 15ded106ef1a cms/app-client/app/templates/player.hbs --- a/cms/app-client/app/templates/player.hbs Mon Jan 18 10:01:39 2016 +0100 +++ b/cms/app-client/app/templates/player.hbs Tue Jan 19 19:06:17 2016 +0100 @@ -1,10 +1,7 @@Title: {{ currentItem.title }}
@@ -12,15 +9,3 @@ Description: {{ currentItem.description }}