Class: Airplay::Player::Media

Inherits:
Object
  • Object
show all
Defined in:
lib/airplay/player/media.rb

Constant Summary collapse

COMPATIBLE_TYPES =
%w(
  application/mp4
  video/mp4
  video/vnd.objectvideo
  video/MP2T
  video/quicktime
  video/mpeg4
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_or_url) ⇒ Media

Returns a new instance of Media.



19
20
21
# File 'lib/airplay/player/media.rb', line 19

def initialize(file_or_url)
  @file_or_url = file_or_url
end

Instance Attribute Details

#file_or_urlObject (readonly)

Returns the value of attribute file_or_url.



8
9
10
# File 'lib/airplay/player/media.rb', line 8

def file_or_url
  @file_or_url
end

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/airplay/player/media.rb', line 8

def url
  @url
end

Instance Method Details

#compatible?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
# File 'lib/airplay/player/media.rb', line 34

def compatible?
  @_compatible ||= begin
    path = File.basename(file_or_url)
    compatibility = MIME::Types.type_for(path).map(&:to_s) & COMPATIBLE_TYPES
    compatibility.any?
  end
end

#local?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/airplay/player/media.rb', line 42

def local?
  File.exists?(file_or_url)
end

#remote?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/airplay/player/media.rb', line 46

def remote?
  !!(file_or_url =~ URI::regexp)
end

#to_sObject



50
# File 'lib/airplay/player/media.rb', line 50

def to_s; url end