backbone-soundmanager2-rails 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 61c95b2e6aea931960661b5e4b17396e36883ffb
4
+ data.tar.gz: 8b4e2da9edfa9a82f844b0c9db43ef957a32c668
5
+ SHA512:
6
+ metadata.gz: 48dc8c9ec157a54c03e9ef6b47cdc10eeda3c0e3dcdb8878e1f914048e078e7752322dcb071a0f9d6c56900956656f3e7fad29ebc3869cb13e5595fe8f7190af
7
+ data.tar.gz: 8d01b6e6324fcbfc02ed57f0e971f3bc419099b19193307d76ed1295cf2c26d4e1d095d25e6bf9e3740dea4a5bc78996bc690e5057749955d9d84f46d67ae139
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in backbone-soundmanager2-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Philipp Bosch
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Backbone::Soundmanager2::Rails
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'backbone-soundmanager2-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install backbone-soundmanager2-rails
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/backbone-soundmanager2-rails/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'backbone/soundmanager2/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "backbone-soundmanager2-rails"
8
+ spec.version = Backbone::Soundmanager2::Rails::VERSION
9
+ spec.authors = ["Philipp Bosch"]
10
+ spec.email = ["hello@pb.io"]
11
+ spec.summary = "backbone.soundmanager2 for Rails"
12
+ spec.description = "backbone.soundmanager2 packaged as a gem for use in Rails' asset pipeline"
13
+ spec.homepage = "https://github.com/philippbosch/backbone-soundmanager2-rails"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "railties", ">= 3.0", "< 5.0"
25
+ end
@@ -0,0 +1,7 @@
1
+ module Backbone
2
+ module Soundmanager2
3
+ module Rails
4
+ VERSION = "0.1.2"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require "backbone/soundmanager2/rails/version"
2
+
3
+ module Backbone
4
+ module Soundmanager2
5
+ module Rails
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,325 @@
1
+ if require?
2
+ Backbone = require "backbone"
3
+ else
4
+ Backbone = window.Backbone
5
+
6
+ # A player model for use with SoundManager2 API. Requires soundmanager2 (duh).
7
+
8
+ class BackboneSoundManager2
9
+
10
+ _.extend this.prototype, Backbone.Events
11
+
12
+ # Create a new Player instance. There will probably only ever be one
13
+ # of these in the app. If `options.bus` is provided, rebroadcast all events
14
+ # to it with a `player:` prefix. Can also accept an 'autoPlay' option if
15
+ # you want the sound to start playing automatically on load.
16
+ #
17
+ # Also rebroadcast messages on the playable, if possible.
18
+ #
19
+ # Examples
20
+ #
21
+ # track = new Track()
22
+ # track.on "player:heyo", myFunction
23
+ #
24
+ # player = new Player()
25
+ # player.playable = track
26
+ # player.trigger "heyo"
27
+ # # => Will execute track.myFunction()
28
+ #
29
+ # Returns self.
30
+
31
+ constructor: (options = {}) ->
32
+ @options = options
33
+
34
+ if @options.bus?
35
+ @on "all", (event, args...) ->
36
+ @options.bus.trigger "player:#{event}", args...
37
+
38
+ @on "all", (event, args...) ->
39
+ return unless @playable?.trigger?
40
+
41
+ @playable.trigger "player:#{event}", args...
42
+
43
+ this
44
+
45
+
46
+ # Release the current sound, clear the current playable, and trigger
47
+ # a `released` event.
48
+ #
49
+ # Examples
50
+ #
51
+ # App.player.release() # => Playable is removed from player.
52
+ #
53
+ # Returns newly changed self.
54
+
55
+ release: ->
56
+ if @sound
57
+ @fadeout =>
58
+ @sound.destruct()
59
+
60
+ @sound = null
61
+
62
+ @trigger "releasing"
63
+
64
+ @playable.release() if @playable?.release?
65
+ @playable = null
66
+
67
+ @trigger "released"
68
+
69
+ this
70
+
71
+ # Fade out the current sound's volume to 0 and run any callbacks.
72
+ #
73
+ # Examples
74
+ #
75
+ # player.fadeout() # => volume smoothly goes to zero.
76
+ #
77
+ # Returns self
78
+
79
+ fadeout: (callback) ->
80
+
81
+ # Fade out started causing issues when the track sharing went in.
82
+ # Removing this ability for now until we can circle back.
83
+
84
+ callback()
85
+ this
86
+
87
+ # Original fade out. Can't get here now.
88
+
89
+ s = @sound
90
+ vol = @volume * 100
91
+
92
+ fnc = =>
93
+ vol -= 2
94
+ s.setVolume vol
95
+ if vol > 0
96
+ _.delay fnc, 10
97
+ else
98
+ callback()
99
+
100
+ fnc()
101
+
102
+ this
103
+
104
+
105
+ # Determine if the state of the player is `paused`, or `playing`.
106
+ #
107
+ # Examples
108
+ #
109
+ # player.toggle track
110
+ # player.getState() # => "playing"
111
+ #
112
+ # Returns String indicating `paused` or `playing` state.
113
+ # Returns null if nothing is currently playing.
114
+
115
+ getState: ->
116
+ return unless @playable?
117
+
118
+ return "loading" unless @sound?
119
+
120
+ return "stopped" if @sound.playState == 0
121
+
122
+ if @sound.paused then "paused" else "playing"
123
+
124
+
125
+ # Determine if current playable is equal to playable passed in.
126
+ #
127
+ # Examples
128
+ #
129
+ # player.load track
130
+ # player.isAlreadyPlaying track # => true
131
+ #
132
+ # Returns boolean.
133
+
134
+ isAlreadyPlaying: (playable) ->
135
+ @playable? and @playable.id == playable.id
136
+
137
+
138
+ # Determine if a sound has already been already loaded.
139
+ #
140
+ # Examples
141
+ #
142
+ # player.load track
143
+ # player.hasSoundLoaded() # => true
144
+ #
145
+ # Returns boolean.
146
+
147
+ hasSoundLoaded: ->
148
+ @sound?
149
+
150
+
151
+ # Test if a `playable` has getAudioURL() method.
152
+ #
153
+ # playable - A model that fulfills the contract of having getAudioURL()
154
+ #
155
+ # Examples
156
+ #
157
+ # track = new Track();
158
+ # track.isPlayable() # => true
159
+ #
160
+ # Returns boolean.
161
+
162
+ isPlayable: (playable) ->
163
+ playable.id? and playable.getAudioURL?
164
+
165
+
166
+ ok: ->
167
+ soundManager.ok()
168
+
169
+ # Load a `playable` and create an SM2 sound instance (@sound) to represent it.
170
+ # Triggers `loading` and `loaded` events. Will also automatically play
171
+ # it's `playable` model.
172
+ #
173
+ # playable - A model that fulfills the contract of having getAudioURL()
174
+ #
175
+ # Examples
176
+ #
177
+ # track = new Track();
178
+ # player.load track
179
+
180
+ load: (playable) ->
181
+ # No need to load the same playable track
182
+ return if playable is @playable
183
+
184
+ unless soundManager.ok()
185
+ return @trigger "error", "SoundManager2 isn't ready."
186
+
187
+ unless @isPlayable playable
188
+ return @trigger "error",
189
+ "Playable doesn't satisfy the contract.", playable
190
+
191
+ @release()
192
+
193
+ @playable = playable
194
+ @playable.retain() if @playable.retain?
195
+
196
+ @trigger "loading"
197
+
198
+ playable.getAudioURL (url) =>
199
+ # It may happen that the playable has
200
+ # changed while fetching url..
201
+ return unless @playable == playable
202
+
203
+ @sound = soundManager.createSound
204
+ autoPlay : false # Trick: we want the "played" event
205
+ # to be emitted after the "loaded"
206
+ # event, so we call `@sound.play()`
207
+ # manually below..
208
+ id : playable.id
209
+ url : url
210
+ volume : Math.round @volume*100
211
+ onfinish : => @trigger "finished", @sound
212
+ onplay : => @trigger "played", @sound
213
+ onpause : => @trigger "paused", @sound
214
+ onresume : => @trigger "resumed", @sound
215
+ onstop : => @trigger "stopped", @sound
216
+ whileplaying : => @trigger "playing", @sound
217
+ whileloading : => @trigger "bytesLoaded", @sound
218
+
219
+ @trigger "loaded", @sound
220
+
221
+ @sound.play() if @options.autoPlay is true
222
+
223
+ # Initial volume
224
+
225
+ volume: 1
226
+
227
+ # Set sound to be a particular volume, accepts values
228
+ # between 0. and 1.
229
+ #
230
+ # volume - a float between 0 and 1.
231
+ #
232
+ # Examples
233
+ #
234
+ # player.sound.volume # => 80
235
+ # player.setVolume 1
236
+ # player.sound.volume # => 100
237
+ #
238
+ # Returns SoundManager2 sound.
239
+
240
+ setVolume: (volume) ->
241
+ return unless @sound?
242
+ return if volume > 1 || volume < 0
243
+
244
+ @volume = volume
245
+ @sound.setVolume Math.round(@volume * 100)
246
+ @sound
247
+
248
+
249
+
250
+ # Move to a specific position in the current sound. `position` is a
251
+ # percentage, expressed as a number between 0 and 1.
252
+ #
253
+ # position - a float between 0 and 1.
254
+ #
255
+ # Examples
256
+ #
257
+ # # for a track with a duration of 5000 milliseconds
258
+ # player.sound.position # => 1000
259
+ # player.setPosition 0.5
260
+ # player.sound.position # => 2500
261
+ #
262
+ # Returns SoundManager2 sound.
263
+
264
+ setPosition: (position) ->
265
+ return unless @sound?
266
+ return if @sound.bytesLoaded / @sound.bytesTotal < position
267
+ @sound.setPosition position * @sound.durationEstimate
268
+ @sound
269
+
270
+ # Move to a position relative to current position, in milliseconds
271
+ #
272
+ # position - a integer..
273
+ #
274
+ # Examples
275
+ #
276
+ # # For a track with a duration of 5000 milliseconds
277
+ # player.sound.position # => 1000
278
+ # player.setRelativePosition -500
279
+ # player.sound.position # => 500
280
+
281
+ setRelativePosition: (position) ->
282
+ return unless @sound?
283
+
284
+ @sound.setPosition @sound.position + position
285
+
286
+
287
+ # Toggle play/pause for the current sound or load a new `playable`.
288
+ #
289
+ # playable - A model that fulfills the contract of having getAudioURL()
290
+ #
291
+ # Examples
292
+ #
293
+ # player.toggle track # => track will load and start playing
294
+
295
+ toggle: (playable = @playable) ->
296
+ if @sound? and @isAlreadyPlaying playable
297
+ @sound.togglePause()
298
+ else if playable?
299
+ @stop()
300
+ @load playable
301
+
302
+
303
+ # Stop for the current sound.
304
+ #
305
+ # Examples
306
+ #
307
+ # player.stop() # => track will stop completely
308
+
309
+ stop: ->
310
+ return unless @sound?
311
+ @sound.stop()
312
+
313
+ pause: ->
314
+ return unless @sound
315
+ @fadeout =>
316
+ @sound.pause()
317
+ @sound.setVolume 100
318
+
319
+ # If we are in Node environment — export our constructor function in a module,
320
+ # else — add it to Backbone object as a property
321
+
322
+ if module? and module.exports?
323
+ module.exports = BackboneSoundManager2
324
+ else
325
+ Backbone.SoundManager2 = BackboneSoundManager2
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: backbone-soundmanager2-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Philipp Bosch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: railties
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '5.0'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '3.0'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '5.0'
61
+ description: backbone.soundmanager2 packaged as a gem for use in Rails' asset pipeline
62
+ email:
63
+ - hello@pb.io
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - ".gitignore"
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - backbone-soundmanager2-rails.gemspec
74
+ - lib/backbone/soundmanager2/rails.rb
75
+ - lib/backbone/soundmanager2/rails/version.rb
76
+ - vendor/assets/javascripts/backbone.soundmanager2.coffee
77
+ homepage: https://github.com/philippbosch/backbone-soundmanager2-rails
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.2.2
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: backbone.soundmanager2 for Rails
101
+ test_files: []