Permalink
Browse files

fixed autostart, animation and looping

  • Loading branch information...
0 parents commit 0e0bff35369ea39499ff533012ea92ebaafdbfc7 GavinM committed Jul 19, 2010
BIN .DS_Store
Binary file not shown.
@@ -0,0 +1 @@
+.DS_Store
@@ -0,0 +1,20 @@
+Copyright (c) 2009 Gavin Morrice
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,43 @@
+=Mp3Player
+
+Here's an mp3_player plugin for Rails.
+Check out http://handyrailstips.com/tips/7-playing-mp3-s-on-your-rails-site-with-mp3_player for more info
+
+To install:
+ script/plugin install git://github.com/GavinM/mp3_player.git
+
+To setup:
+ script/generate mp3_player [name of your mp3 directory]
+
+This adds 'player.swf' to <em>public/</em> and creates a new folder for storing all of your audio files.
+
+==Example Usage
+
+To play an mp3 file found in _public/mp3s/mysong.mp3_ simply add <%= mp3_player("mp3s/mysong.mp3") %> to your view.
+
+If you're using paperclip: <%= mp3_player @my_model.mp3.url %>.
+
+Below is a list of the extra options you can specify:
+(All colors should be expressed as hexadecimal values minus the '#'.
+eg. <%= mp3_player @my_model.mp3.url, :bg => "99FFFF") %>
+
+[:width] width of the player when open in pixels, defaults to 290
+[:class] class of the div wrapping the player, defaults to "mp3_player"
+[:bg] background colour, defaults to "BBBBBB"
+[:left_bg] background colour of the left tab, defaults to "AAAAAA"
+[:right_bg] background colour of the right tab, defaults to "AAAAAA"
+[:right_bg_hover] colour of the right background as the cursor hovers over, defaults to "EEEEEE"
+[:left_icon] the colour of the speaker icon on the left, defaults to "222222"
+[:right_icon] colour of the play/pause icon on the right, defaults to "222222"
+[:right_icon_hover] colour of the play/pause icon as the cursor hovers over, defaults to "222222"
+[:text] colour of the text, defaults to "222222"
+[:slider] colour of the slider bar, defaults to "333333"
+[:loader] colour of the loaded data so far, defaults to "DDDFFF"
+[:track] colour of the track on the slider, defaults to "888888"
+[:border] colour of the buffer border, defaults to "333333"
+
+This plugin is based on the Audio Player Worpress Plugin by Martin Laine http://www.1pixelout.net/code/audio-player-wordpress-plugin
+
+Thanks to Matt Ittigson (http://github.com/mattenat) for inspiring changes to help support paperclip.
+
+Copyright © 2009 Gavin Morrice (http://handyrailstips.com), released under the MIT license
@@ -0,0 +1,27 @@
+# :nodoc:
+class Mp3PlayerGenerator < Rails::Generator::Base
+
+ attr_accessor :audio_dirname
+
+ def initialize(runtime_args, runtime_options = {})
+ # specify the name of the audio directory
+ filename = runtime_args.split(/\s+/).first
+ filename.chop! if filename.last == "/"
+ self.audio_dirname = filename.blank? ? "audio" : filename
+ super
+ end
+
+ def manifest
+ record do |m|
+ m.directory('public')
+ m.file('player.swf', 'public/player.swf')
+ m.directory("public/#{audio_dirname}")
+ m.file("test.mp3", "public/#{audio_dirname}/test.mp3")
+ end
+ end
+
+ def usage_message
+ "to generate files for mp3_player use script/generate mp3_player [audio_file_name]
+ eg. - script/generate mp3_player my_mp3s # => creates public/my_mp3s"
+ end
+end
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
+require "mp3_player/view_helper"
+# includes the view helper to ActionView::Base
+ActionView::Base.send(:include, Mp3Player::ViewHelper)
Binary file not shown.
@@ -0,0 +1 @@
+module Mp3Player;end
@@ -0,0 +1,109 @@
+require "uri"
+module Mp3Player
+
+ # This module contains the view helper <tt>mp3_player</tt>
+ module ViewHelper
+
+ # These are the names of the colour params you can set to style the mp3_player
+ # (all colours should be expressed as 6 figure hex values minus the '#')
+ # * :bg => background colour
+ # * :left_bg => background color of the left tab
+ # * :right_bg => background colour of the right tab
+ # * :right_bg_hover => colour of the right background as the cursor hovers over
+ # * :left_icon => the color of the speaker icon on the left
+ # * :right_icon => colour of the play/pause icon on the right
+ # * :right_icon_hover => colour of the play/pause icon as the cursor hovers over
+ # * :text => colour of the text
+ # * :slider => colour of the slider bar
+ # * :loader => colour of the loaded data so far
+ # * :track => colour of the track on the slider
+ # * :border => colour of the buffer border
+ COLOR_OPTIONS = {
+ :bg => "BBBBBB",
+ :left_bg => "AAAAAA",
+ :right_bg => "AAAAAA",
+ :right_bg_hover => "EEEEEE",
+ :left_icon => "222222",
+ :right_icon => "222222",
+ :right_icon_hover => "222222",
+ :text => "222222",
+ :slider => "333333",
+ :loader => "DDDFFF",
+ :track => "888888",
+ :border => "333333",
+ }
+
+ # These options are boolean values that should be converted to "yes" or "no" for the flash object
+ # * :autostart => should the track start playing on page load?
+ # * :loop => should the track loop continuously?
+ # * :animation => should the mp3 player open when clicked?
+ BOOLEAN_OPTIONS = {
+ :autostart => false,
+ :loop => false,
+ :animation => true,
+ }
+
+ # * :width => width of the player when open in pixels
+ # * :class => class of the div wrapping the player
+ OTHER_OPTIONS = {
+ :width => 290,
+ :class => "mp3_player"
+ }
+
+ # This is the helper method you'll call in the view. <tt><%= mp3_player @song.mp3.url %></tt>
+ # See the options above for more info on customising the player to match your site
+ def mp3_player(path_to_file, options = {})
+ # convert booleans to 'yes'/'no'
+ BOOLEAN_OPTIONS.each {|key, value| options[key] ? options[key] = "yes" : options[key] = "no"}
+
+ # set defaults
+ default_options = COLOR_OPTIONS.merge(BOOLEAN_OPTIONS.merge(OTHER_OPTIONS))
+ options.reverse_merge! default_options
+
+ # ensure options are valid
+ options.assert_valid_keys(default_options.keys)
+
+ # extract color options
+ color_options = options.select {|key,value| COLOR_OPTIONS.include?(key) }
+
+ # extract boolean options
+ boolean_options = options.select {|key,value| BOOLEAN_OPTIONS.include?(key) }
+
+ # add '0x' to colors and add color params
+ flash_vars = color_options.collect {|key, value| "#{key.to_s.gsub("_", "")}=0x#{value}" }
+
+ # add boolean params
+ flash_vars += boolean_options.collect {|key,value| "#{key}=#{value}" }
+
+ # add the soundFile param
+ flash_vars << "soundFile=#{path_to_file}"
+
+ # join params with an ampersand
+ flash_vars = flash_vars.join("&").to_s
+
+ # turn the whole thing into a meaty string
+ output = <<-HTML
+ <div class=\"#{options[:class]}\" id=\"mp3_player_#{player_count}\">
+ <object type="application/x-shockwave-flash" data="/player.swf" height="24" width=\"#{options[:width]}\">
+ <param name="movie" value="/player.swf" />
+ <param name="FlashVars" value="#{URI.escape flash_vars}" />
+ <param name="quality" value="high" />
+ <param name="menu" value="true" />
+ <param name="wmode" value="transparent" />
+ </object>
+ </div>
+ HTML
+ output # => your awesome mp3_player
+ end
+
+ module_function :mp3_player
+
+ def increment_player_count
+ @player_count ||= 0
+ @player_count += 1
+ end
+
+ attr_reader :player_count
+ end
+
+end

0 comments on commit 0e0bff3

Please sign in to comment.