Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View app.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
App = Ember.Application.create();
 
App.Store = DS.Store.extend({
adapter: 'DS.FixtureAdapter'
});
 
App.Router.map(function () {
this.resource('songs');
this.resource('song', { path: '/song/:song_id' });
});
 
App.IndexRoute = Ember.Route.extend({
redirect: function() { this.transitionTo('songs'); }
});
 
App.SongsRoute = Ember.Route.extend({
model: function() {
return App.Song.find();
}
});
 
App.SongRoute = Ember.Route.extend({
model: function(params) {
return App.Song.find(params.song_id);
}
});
 
App.Song = DS.Model.extend({
url: DS.attr('string')
});
 
App.SongController = Ember.ObjectController.extend({
started: false,
 
loadSound: function() {
var self = this;
var sound = soundManager.createSound({
url: this.get('url'),
onfinish: function() { self.finish(); },
whileplaying: function() { self.tick(); },
onload: function() {
self.set('position', 0);
self.set('duration', this.duration);
}
});
 
this.set('sound', sound);
sound.load();
},
 
playPause: function() {
if (this.get('playing')) {
this.pause();
} else {
this.play();
}
},
 
stop: function() {
this.get('sound').stop();
this.finish();
},
 
play: function() {
var sound = this.get('sound');
 
if (this.get('unstarted')) {
sound.play();
this.set('started', true);
} else {
sound.resume();
}
 
this.set('playing', true);
},
 
pause: function() {
this.get('sound').pause();
this.set('playing', false);
},
 
tick: function() {
this.set('position', this.get('sound').position);
},
 
finish: function() {
this.set('position', 0);
this.set('playing', false);
this.set('started', false);
},
 
playPauseLink: function() {
if (this.get('playing')) {
return 'Pause';
} else {
return 'Play'
}
}.property('playing'),
 
unstarted: function() {
return !this.get('started');
}.property('started')
});
 
App.SongView = Ember.View.extend({
didInsertElement: function() {
var self = this;
 
soundManager.onready(function() {
self.get('controller').send('loadSound');
});
}
});
 
App.initializer({
name: "soundmanager",
initialize: function() {
soundManager.setup({
url: '/swf'
});
}
});
 
App.Song.FIXTURES = [
{
id: 1,
url: '/mp3/going_outside.mp3'
}
]
View app.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
<!DOCTYPE html>
<html>
<head>
<script src="/javascripts/lib/jquery-1.9.1.js"></script>
<script src="/javascripts/lib/handlebars.js"></script>
<script src="/javascripts/lib/ember-1.0.0-rc.5.js"></script>
<script src="/javascripts/lib/ember-data-0.13.js"></script>
<script src="/javascripts/lib/bootstrap.js"></script>
<script src="/javascripts/lib/soundmanager2.js"></script>
<script src="/javascripts/app.js"></script>
<link href="/stylesheets/lib/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="/stylesheets/lib/bootstrap-responsive.css" rel="stylesheet" type="text/css" />
<meta charset=utf-8 />
<title>Ember - SoundManager</title>
</head>
<body>
<script type="text/x-handlebars">
<div class="container">
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<ul class="nav">
<li class="active">{{#linkTo 'songs'}}Songs{{/linkTo}}</li>
</ul>
</div>
</div>
</div>
{{outlet}}
</div>
</script>
 
<script type="text/x-handlebars" id="songs">
{{#each model}}
Path: {{url}}
{{#linkTo 'song' this}}Listen{{/linkTo}}
{{/each}}
</script>
 
<script type="text/x-handlebars" id="song">
<p>{{position}} of {{duration}}</p>
<button class="btn" {{action 'playPause'}}>{{playPauseLink}}</button>
<button class="btn" {{action 'stop'}} {{bindAttr disabled="unstarted"}}>Stop</button>
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.