Class: AirPlayer::Media

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ Media

Returns a new instance of Media.



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/airplayer/media.rb', line 25

def initialize(target)
  path   = File.expand_path(target)
  @title = File.basename(path)

  if File.exist? path
    @video_server = AirPlayer::Server.new(path)
    @path = @video_server.uri
    @type = :file
  else
    @path = URI.encode(target)
    @type = :url
  end
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



23
24
25
# File 'lib/airplayer/media.rb', line 23

def path
  @path
end

#titleObject (readonly)

Returns the value of attribute title.



23
24
25
# File 'lib/airplayer/media.rb', line 23

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



23
24
25
# File 'lib/airplayer/media.rb', line 23

def type
  @type
end

Class Method Details

.playable?(path) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
# File 'lib/airplayer/media.rb', line 39

def self.playable?(path)
  MIME::Types.type_for(path).each do |mimetype|
    return SUPPORTED_MIME_TYPES.include? mimetype
  end
  false
end

Instance Method Details

#closeObject



51
52
53
# File 'lib/airplayer/media.rb', line 51

def close
  @video_server.stop if file?
end

#file?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/airplayer/media.rb', line 55

def file?
  @type == :file
end

#openObject



46
47
48
49
# File 'lib/airplayer/media.rb', line 46

def open
  Thread.start { @video_server.start } if file?
  @path
end

#url?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/airplayer/media.rb', line 59

def url?
  @type == :url
end