Class: Mplayer

Inherits:
Player show all
Defined in:
lib/player/mplayer.rb

Constant Summary collapse

WAIT_LIMIT =
3

Instance Method Summary collapse

Methods inherited from Player

#duration

Constructor Details

#initialize(url) ⇒ Mplayer

Returns a new instance of Mplayer.



10
11
12
13
14
15
# File 'lib/player/mplayer.rb', line 10

def initialize(url)
	@url=url
	self['cache']     = 64
	self['cache-min'] = 16
	self['quiet']     = ''      # 画面表示をしない
end

Instance Method Details

#commandObject



18
19
20
# File 'lib/player/mplayer.rb', line 18

def command
	'mplayer'
end

#optionsObject



22
23
24
# File 'lib/player/mplayer.rb', line 22

def options
	map{ |k,v| "-#{k} #{v}"}*' '
end

#playObject



32
33
34
35
# File 'lib/player/mplayer.rb', line 32

def play
	puts to_s
	`#{to_s}`
end

#rec(file, sec, quiet = true) ⇒ Object



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
# File 'lib/player/mplayer.rb', line 38

def rec(file, sec, quiet = true)
	self['dumpstream'] = ''
	self['dumpfile']   = %Q("#{file}")
	if quiet
		self['nosound'] = ''	# 音声を再生しない
	end

	puts "rec (#{sec}s): #{to_s}"
	stdin, stdout, stderr, wait_thread = Open3.popen3(to_s)
	dsec = -1
	psec = dsec
	wait = 0
	i = 0
	while dsec <= sec
		dsec = duration(file)
		if dsec == psec
			wait += 1
			break if wait > WAIT_LIMIT
		else
			wait = 0
			psec = dsec
		end
		p [i, dsec, psec, wait] if wait > 0
		i += 1
		sleep 1
	end
	stdin.write 'q'
end

#to_sObject



27
28
29
# File 'lib/player/mplayer.rb', line 27

def to_s
	%Q(#{command} #{@url} #{options} )
end