simple_audioplayer 1.0.0
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.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +66 -0
- data/Rakefile +2 -0
- data/app/assets/javascripts/simple_audioplayer.js.coffee +201 -0
- data/lib/simple_audioplayer/version.rb +3 -0
- data/lib/simple_audioplayer.rb +9 -0
- data/public/sm2_swf/soundmanager2.swf +0 -0
- data/public/sm2_swf/soundmanager2_debug.swf +0 -0
- data/public/sm2_swf/soundmanager2_flash9.swf +0 -0
- data/public/sm2_swf/soundmanager2_flash9_debug.swf +0 -0
- data/public/sm2_swf/soundmanager2_flash_xdomain.zip +0 -0
- data/simple_audioplayer.gemspec +17 -0
- data/vendor/assets/javascripts/soundmanager2-nodebug.js +2380 -0
- data/vendor/assets/javascripts/soundmanager2.js +5026 -0
- metadata +64 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Semenyuk Dmitriy
|
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,66 @@
|
|
1
|
+
# Simple Audioplayer
|
2
|
+
|
3
|
+
Simple audioplayer for Rails apps, based on SoundManager2, has support for playlists.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'simple_audioplayer'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install simple_audioplayer
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Include this line to your app/assets/application.js:
|
22
|
+
|
23
|
+
//= require simple_audioplayer
|
24
|
+
|
25
|
+
or
|
26
|
+
|
27
|
+
#= require simple_audioplayer
|
28
|
+
|
29
|
+
if you use CoffeeScript (application.js.coffee).
|
30
|
+
|
31
|
+
|
32
|
+
Example expalins it better:
|
33
|
+
|
34
|
+
<div>
|
35
|
+
<a data-behavior="player_switch_to_prev_track" href="#">PREV</a>
|
36
|
+
|
|
37
|
+
<a data-behavior="play_first_or_existing_track_on_page" href="#">PLAY</a>
|
38
|
+
|
|
39
|
+
<a data-behavior="player_switch_to_next_track" href="#">NEXT</a>
|
40
|
+
<ul data-music-container>
|
41
|
+
<li data-track-container>
|
42
|
+
<a data-audio-track data-behavior="play_audio_track" data-id="1" data-title="Coldplay - Viva La Vida" data-url="/music/my_track.mp3" href="#">
|
43
|
+
<i class="icon-play"></i>
|
44
|
+
</a>
|
45
|
+
<span>
|
46
|
+
Coldplay - Viva La Vida
|
47
|
+
</span>
|
48
|
+
</li>
|
49
|
+
|
50
|
+
<li data-track-container>
|
51
|
+
...
|
52
|
+
</li>
|
53
|
+
</ul>
|
54
|
+
</div>
|
55
|
+
|
56
|
+
*Note:*
|
57
|
+
|
58
|
+
Please copy `public/sm2_swf` to your `public/` catalog (`sm2_swf` catalog contains flash audioplayers for cases when HTML5 Audio MP3 support isn't available). You can find it on GitHub: http://github.com/dmitrydims/simple_audioplayer.
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
1. Fork it
|
63
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
65
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
66
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
#= require soundmanager2-nodebug
|
2
|
+
|
3
|
+
$ ->
|
4
|
+
new AudioPlayer
|
5
|
+
|
6
|
+
class AudioPlayer
|
7
|
+
constructor: (params) ->
|
8
|
+
that = this
|
9
|
+
soundManager.url = params['url'] || '/sm2_swf/'
|
10
|
+
soundManager.defaultOptions.autoPlay = true
|
11
|
+
soundManager.preferFlash = false
|
12
|
+
|
13
|
+
soundManager.ontimeout ->
|
14
|
+
console.error "SoundManager: I can't start."
|
15
|
+
|
16
|
+
$(document).on 'click', '[data-behavior~=player_switch_to_prev_track]', (e) ->
|
17
|
+
that.prevTrack()
|
18
|
+
|
19
|
+
$(document).on 'click', '[data-behavior~=player_switch_to_next_track]', (e) ->
|
20
|
+
that.nextTrack()
|
21
|
+
|
22
|
+
$(document).on 'click', '[data-behavior~=play_audio_track]', (event) ->
|
23
|
+
event.preventDefault()
|
24
|
+
|
25
|
+
unless that.checkIfMusicCanBePlayed()
|
26
|
+
console.log "SM2: I can't play audios"
|
27
|
+
return false
|
28
|
+
|
29
|
+
that.playTrack this
|
30
|
+
|
31
|
+
$(document).on 'click', '[data-behavior~=play_first_or_existing_track_on_page]', (event) ->
|
32
|
+
event.preventDefault()
|
33
|
+
|
34
|
+
unless that.checkIfMusicCanBePlayed()
|
35
|
+
console.log "I can't play audios"
|
36
|
+
return false
|
37
|
+
|
38
|
+
that.togglePlayPauseOrPlayFirstTrack()
|
39
|
+
|
40
|
+
soundManager.onready ->
|
41
|
+
tracklist = $('[data-audio-track]')
|
42
|
+
|
43
|
+
checkIfMusicCanBePlayed: ->
|
44
|
+
unless soundManager.ok()
|
45
|
+
if confirm 'Для воспроизведения музыки необходимо установить Flash-плеер. Перейти на страницу установки (откроется во всплывающем окне)?'
|
46
|
+
window.open 'http://get.adobe.com/flash'
|
47
|
+
false
|
48
|
+
else
|
49
|
+
true
|
50
|
+
|
51
|
+
tunePlayPauseButtons: (element) =>
|
52
|
+
i = $(element).find('i')
|
53
|
+
yea = i.hasClass('icon-play')
|
54
|
+
|
55
|
+
this.setAllPlayPauseButtonsToPlay()
|
56
|
+
|
57
|
+
# hack
|
58
|
+
if yea
|
59
|
+
i.removeClass 'icon-play'
|
60
|
+
i.addClass 'icon-pause'
|
61
|
+
else
|
62
|
+
i.addClass 'icon-play'
|
63
|
+
i.removeClass 'icon-pause'
|
64
|
+
|
65
|
+
setAllPlayPauseButtonsToPlay: ->
|
66
|
+
$('[data-track-container] i').removeClass('icon-pause').addClass('icon-play')
|
67
|
+
|
68
|
+
togglePlayPauseOrPlayFirstTrack: ->
|
69
|
+
that = this
|
70
|
+
# контейнер с аудиоэлементами
|
71
|
+
audioContainer = that.getAudioContainer()
|
72
|
+
|
73
|
+
if that.currentTrackId
|
74
|
+
currentTrackId = that.currentTrackId
|
75
|
+
else
|
76
|
+
# первый трэк, который нужно будет начать играть, если
|
77
|
+
# ни один из других трэков сейчас не играет
|
78
|
+
firstTrack = $('[data-audio-track]:eq(0)')
|
79
|
+
firstTrackId = firstTrack.data('id')
|
80
|
+
currentTrackId = soundManager.getSoundById(firstTrackId)
|
81
|
+
|
82
|
+
thereIsSomePlayingTrack = false
|
83
|
+
for id, sound of soundManager.sounds
|
84
|
+
if sound.sID == currentTrackId
|
85
|
+
thereIsSomePlayingTrack = true
|
86
|
+
console.log 'resuming/pausing track with ID: ', currentTrackId
|
87
|
+
elem = $("[data-audio-track][data-id=#{currentTrackId}]")
|
88
|
+
elem.click()
|
89
|
+
else
|
90
|
+
sound.stop()
|
91
|
+
|
92
|
+
unless thereIsSomePlayingTrack
|
93
|
+
that.playFirstTrack()
|
94
|
+
console.log('playing first track')
|
95
|
+
|
96
|
+
playFirstTrack: =>
|
97
|
+
firstTrackElement = $('[data-audio-track]:eq(0)')
|
98
|
+
firstTrackElement.click()
|
99
|
+
console.log('playing first thack (no previous track found)')
|
100
|
+
|
101
|
+
|
102
|
+
playTrack: (element) =>
|
103
|
+
_this = this
|
104
|
+
data = $(element).data()
|
105
|
+
trackId = data.id
|
106
|
+
trackSource = data.url
|
107
|
+
trackTitle = data.title
|
108
|
+
currentTrack = soundManager.getSoundById(trackId)
|
109
|
+
|
110
|
+
@tunePlayPauseButtons(element)
|
111
|
+
|
112
|
+
try
|
113
|
+
$('.current_track_title').text trackTitle
|
114
|
+
catch err
|
115
|
+
|
116
|
+
@setNextPrevTrackElements(element)
|
117
|
+
|
118
|
+
if currentTrack
|
119
|
+
for id, sound of soundManager.sounds
|
120
|
+
if sound.sID == trackId
|
121
|
+
if sound.paused
|
122
|
+
#console.log 'resuming track: ', trackId
|
123
|
+
else
|
124
|
+
#console.log 'pausing track: ', trackId
|
125
|
+
sound.togglePause()
|
126
|
+
else
|
127
|
+
sound.stop()
|
128
|
+
else
|
129
|
+
soundManager.stopAll()
|
130
|
+
#console.log 'playing track with ID: ', trackId
|
131
|
+
soundManager.createSound(
|
132
|
+
id: trackId
|
133
|
+
url: trackSource
|
134
|
+
volume: 50
|
135
|
+
whileplaying: ->
|
136
|
+
try
|
137
|
+
_this.updateTime this
|
138
|
+
catch err
|
139
|
+
console.log err
|
140
|
+
onfinish: ->
|
141
|
+
_this.setAllPlayPauseButtonsToPlay()
|
142
|
+
_this.nextTrack(playFirstTrackIfNoNextTrack = false)
|
143
|
+
).play()
|
144
|
+
_this.currentTrackId = trackId
|
145
|
+
|
146
|
+
nextTrack: (playFirstTrackIfNoNextTrack = true) ->
|
147
|
+
if @nextTrackElement
|
148
|
+
@nextTrackElement.find('[data-audio-track]').click()
|
149
|
+
#console.log 'NEXT: ', @nextTrackElement
|
150
|
+
else
|
151
|
+
#console.log 'NO NEXT'
|
152
|
+
if playFirstTrackIfNoNextTrack
|
153
|
+
@playFirstTrack()
|
154
|
+
else
|
155
|
+
@currentTrackId = null
|
156
|
+
|
157
|
+
prevTrack: ->
|
158
|
+
if @prevTrackElement
|
159
|
+
@prevTrackElement.find('[data-audio-track]').click()
|
160
|
+
#console.log 'PREV: ', @prevTrackElement
|
161
|
+
else
|
162
|
+
#console.log 'NO PREV'
|
163
|
+
|
164
|
+
setNextPrevTrackElements: (currentTrackElement) ->
|
165
|
+
audioContainer = $('[data-music-container]')
|
166
|
+
trackContainer = $(currentTrackElement).closest('[data-track-container]')
|
167
|
+
indexOfTrackInPlaylist = trackContainer.index()
|
168
|
+
|
169
|
+
nextTrackIndex = indexOfTrackInPlaylist + 1
|
170
|
+
prevTrackIndex = indexOfTrackInPlaylist - 1
|
171
|
+
nextTrack = audioContainer.find("[data-track-container]:eq(#{nextTrackIndex})")
|
172
|
+
prevTrack = audioContainer.find("[data-track-container]:eq(#{prevTrackIndex})")
|
173
|
+
if nextTrack.length > 0
|
174
|
+
#console.log("Next track: ", nextTrack)
|
175
|
+
@nextTrackElement = nextTrack
|
176
|
+
else
|
177
|
+
#console.log("No next track")
|
178
|
+
@nextTrackElement = null
|
179
|
+
|
180
|
+
if prevTrack.length > 0
|
181
|
+
#console.log("prev track: ", prevTrack)
|
182
|
+
@prevTrackElement = prevTrack
|
183
|
+
else
|
184
|
+
#console.log("No prev track")
|
185
|
+
@prevTrackElement = null
|
186
|
+
|
187
|
+
getAudioContainer: ->
|
188
|
+
$('[data-music-container]')
|
189
|
+
|
190
|
+
humanizeSeconds: (seconds) ->
|
191
|
+
minutes = parseInt(seconds / 60, 10)
|
192
|
+
seconds = parseInt(seconds % 60, 10)
|
193
|
+
seconds = "0#{seconds}" if seconds < 10
|
194
|
+
|
195
|
+
minutes: minutes
|
196
|
+
seconds: seconds
|
197
|
+
|
198
|
+
updateTime: (obj) ->
|
199
|
+
# TODO
|
200
|
+
changeVolume: ->
|
201
|
+
# TODO
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/simple_audioplayer/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Dims"]
|
6
|
+
gem.email = ["mail@dims.kz"]
|
7
|
+
gem.description = %q{Simple audioplayer based on SoundManager2}
|
8
|
+
gem.summary = %q{Based on SoundManager2, supports playlists}
|
9
|
+
gem.homepage = "http://dims.kz"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "simple_audioplayer"
|
15
|
+
gem.require_paths = ["lib", "app", "vendor"]
|
16
|
+
gem.version = SimpleAudioplayer::VERSION
|
17
|
+
end
|