Skip to content

Instantly share code, notes, and snippets.

@rjungemann
Created January 28, 2010 07:01
Show Gist options
  • Save rjungemann/288508 to your computer and use it in GitHub Desktop.
Save rjungemann/288508 to your computer and use it in GitHub Desktop.
script for making audio or video playlists which play in the browser, but which also work as playlists on the iPhone.
# script for making audio or video playlists which play in the browser
# but which also work as playlists on the iPhone.
#
# example:
# playlist %w[one.mp3 two.mp3 three.mp3]
#
# sources:
# http://stackoverflow.com/questions/87290/how-to-embed-audio-video-on-html-page-that-plays-on-iphone-browser-over-gprs
# http://broadcast.oreilly.com/2009/04/iphone-web-audio-playlistshtml.html
# http://jchrisa.net/drl/_design/sofa/_show/post/web_audio_for_the_iphone
# http://www.apple.com/quicktime/tutorials/embed.html
def playlist urls, opts = {}
options = ({
:width => 128,
:height => 16,
:type => "audio/mp3",
:image => "listen.jpeg",
:loop => false
}).merge opts
i = 0
ie_files = urls[1..-1].collect { |url|
i += 1
"'qtnext#{i}', '<#{url}>T<myself>'"
}.join ", "
i = 0
files = urls[1..-1].collect { |url|
i += 1
"'qtnext#{i}=\"<#{url}> T<myself>\""
}.join " "
%{
<script language="JavaScript" type="text/javascript">
//<![CDATA[
QT_WriteOBJECT('#{options[:image]}', '#{options[:width]}', '#{options[:height]}', '',
'controller', 'false', 'scale', 'aspect', 'target', 'myself', 'autoplay', 'true',
'loop', '#{options[:loop]}', 'type', '#{options[:type]}',
'href', '#{urls.first}',
#{ie_files}
);
//]]>
</script>
<embed target="myself" src="#{options[:image]}" href="#{urls.first}"
width="#{options[:width]}" height="#{options[:height]}" autoplay="true"
type="#{options[:type]}" loop="#{options[:loop]}"
controller="false" #{files}
></embed>
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment