lib/airplayer/media.rb in airplayer-0.0.3 vs lib/airplayer/media.rb in airplayer-0.0.4

- old
+ new

@@ -1,8 +1,26 @@ require 'uri' +require 'mime/types' module AirPlayer + # http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/AirPlayGuide/PreparingYourMediaforAirPlay/PreparingYourMediaforAirPlay.html + # + # File Extension | MIME type | Ruby `mime-types` + # -------------- | --------------- | ----------------------------- + # .ts | video/MP2T | video/MP2T + # .mov | video/quicktime | video/quicktime + # .m4v | video/mpeg4 | video/vnd.objectvideo + # .mp4 | video/mpeg4 | application/mp4, video/mp4 + SUPPORTED_MIME_TYPES = %w[ + application/mp4 + video/mp4 + video/vnd.objectvideo + video/MP2T + video/quicktime + video/mpeg4 + ] + class Media attr_reader :title, :path, :type def initialize(target) path = File.expand_path(target) @@ -14,9 +32,16 @@ @type = :file else @path = URI.encode(target) @type = :url end + end + + def self.playable?(path) + MIME::Types.type_for(path).each do |mimetype| + return SUPPORTED_MIME_TYPES.include? mimetype + end + false end def open Thread.start { @video_server.start } if file? @path