Class: RMPlayer::App
- Inherits:
-
Object
- Object
- RMPlayer::App
- Defined in:
- lib/rmplayer/app.rb
Instance Method Summary collapse
- #browse(dir) ⇒ Object
- #quit_mplayer ⇒ Object
- #run(args) ⇒ Object
- #show_file?(file, name) ⇒ Boolean
- #status ⇒ Object
Instance Method Details
#browse(dir) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/rmplayer/app.rb', line 114 def browse(dir) base = File.(dir) files = Dir.new(base).entries.sort xml = Builder::XmlMarkup.new xml.root do files.each do |name| f = "#{base}/#{name}" next unless show_file?(f, name) xml.element :type => (File.directory?(f) ? 'directory' : 'file'), :size => File.size(f), :date => File.mtime(f), :path => f, :name => File.basename(f), :extension => File.extname(f) end end puts xml.target! if DEBUG xml.target! end |
#quit_mplayer ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/rmplayer/app.rb', line 80 def quit_mplayer if @mplayer begin @mplayer.quit @mplayer = nil rescue Exception => ignore ensure @mplayer = nil end end end |
#run(args) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rmplayer/app.rb', line 14 def run(args) @mplayer = MPlayer.new(args) s = ::WEBrick::HTTPServer.new(:Port => 8080, :MaxClients => 5, :DoNotReverseLookup => true, :ShutdownSocketWithoutClose => true, :Logger => DEBUG ? nil : NullLogger.new) s.mount_proc('/requests/status.xml') do |req, resp| begin command = req.query['command'] || 'status' puts "Executing #{command}" if DEBUG case command when 'in_play' file = req.query['input'] if @mplayer @mplayer.load_file file else @mplayer = MPlayer.new file end when 'fullscreen' @mplayer.toggle_fullscreen when 'seek' val = req.query['val'].to_i @mplayer.seek(val) when 'volume' val = req.query['val'].to_i @mplayer.volume = ((val * 100.0) / 1024).to_i when 'pl_next' when 'pl_previous' when 'pl_pause', 'pl_play' @mplayer.pause when 'pl_stop' quit_mplayer end resp.status = 200 resp['Content-Type'] = 'text/xml' resp.body = status rescue Errno::EPIPE => ex quit_mplayer resp.status = 500 end end s.mount_proc('/requests/browse.xml') do |req, resp| dir = req.query['dir'] resp.status = 200 resp['Content-Type'] = 'text/xml' resp.body = browse(dir) end trap("INT") do quit_mplayer s.shutdown end Socket.do_not_reverse_lookup = true s.start end |
#show_file?(file, name) ⇒ Boolean
138 139 140 141 142 143 |
# File 'lib/rmplayer/app.rb', line 138 def show_file?(file, name) return true if name == '..' return false if name[0, 1] == '.' return true if File.directory?(file) return %w(.avi .mpg .mpeg .mk4 .mov .ogg .mp3).include?(File.extname(name)) end |
#status ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rmplayer/app.rb', line 92 def status xml = Builder::XmlMarkup.new xml.root do xml.volume @mplayer ? ((@mplayer.volume.to_i * 1024.0) / 100).to_i : 256 xml.length @mplayer ? @mplayer.time_length.to_i : 0 xml.time @mplayer ? @mplayer.time_pos.to_i : 0 xml.state @mplayer ? (@mplayer.paused? ? 'paused' : 'playing') : 'stop' xml.position @mplayer ? @mplayer.percent_pos.to_i : 0 xml.fullscreen xml.loop 0 xml.repeat 0 xml.information do xml.tag! :'meta-information' do xml.title @mplayer ? @mplayer.file_name : '' end end end puts xml.target! if DEBUG xml.target! end |