easy_mplayer 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
data/easy_mplayer.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{easy_mplayer}
8
- s.version = "1.1.0"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brent Sanders"]
12
- s.date = %q{2010-01-09}
12
+ s.date = %q{2010-01-10}
13
13
  s.description = %q{A wrapper to manage mplayer, that supports callbacks to easily support event-driven GUIs}
14
14
  s.email = %q{gem-mplayer@thoughtnoise.net}
15
15
  s.extra_rdoc_files = [
@@ -4,7 +4,6 @@ class MPlayer
4
4
  :program => '/usr/bin/mplayer',
5
5
  :message_style => :info,
6
6
  :seek_size => 10,
7
- :select_wait_time => 1,
8
7
  :thread_safe_callbacks => true
9
8
  }
10
9
 
@@ -59,8 +58,6 @@ class MPlayer
59
58
  # :seek_size Time, in seconds, to seek
60
59
  # forwards/reverse by default (default:
61
60
  # 10 seconds)
62
- # :select_wait_time Time, in seconds, for blocking on
63
- # IO.select in the worker threads (default: 1)
64
61
  # :thread_safe_callbacks If we should buffer callbacks back to
65
62
  # the main thread, so they are called off
66
63
  # the #playing? polling-loop (default: true)
@@ -91,16 +88,6 @@ class MPlayer
91
88
  stop!
92
89
  end
93
90
 
94
- callback :played_time do |played_time|
95
- update_stat :played_seconds, played_time.to_i
96
- total = stats[:total_time]
97
- if total and total != 0.0
98
- pos = (100 * played_time / total)
99
- update_stat :raw_position, pos
100
- update_stat :position, pos.to_i
101
- end
102
- end
103
-
104
91
  callback :startup do
105
92
  callback! :play
106
93
  end
@@ -1,3 +1,5 @@
1
+ require 'fcntl'
2
+
1
3
  class MPlayer
2
4
  class Worker # :nodoc:all
3
5
  include ColorDebugMessages
@@ -18,9 +20,17 @@ class MPlayer
18
20
  :re => /^ICY Info: StreamTitle='(.*?)';StreamUrl='(.*?)';/,
19
21
  :stat => [:stream_title, :stream_url]
20
22
  },
21
- :update_position => {
22
- :re => /^A:\s+(\d+\.\d+)\s+\(\S+\)\s+of\s+(\d+\.\d+)/,
23
- :stat => [:played_time, :total_time],
23
+ :position_percent => {
24
+ :re => /^ANS_PERCENT_POSITION=(\d+[.0-9]*)/,
25
+ :stat => [:position]
26
+ },
27
+ :position_seconds => {
28
+ :re => /^ANS_TIME_POSITION=(\d+[.0-9]*)/,
29
+ :stat => [:played_seconds]
30
+ },
31
+ :total_time => {
32
+ :re => /^ANS_LENGTH=(\d+[.0-9]*)/,
33
+ :stat => [:total_time]
24
34
  },
25
35
  :audio_info => {
26
36
  :re => /^AUDIO: (\d+) Hz, (\d+) ch, (\S+), ([0-9.]+) kbit/,
@@ -131,28 +141,24 @@ class MPlayer
131
141
  end
132
142
  end
133
143
 
134
- def process_line
135
- # debug "LINE> \"#{@line}\""
136
- send "process_#{@type}", @line
137
- # callback! @type, @line
138
- @line = ''
144
+ def process_line(line)
145
+ # debug "LINE> \"#{line}\""
146
+ send "process_#{@type}", line
147
+ # callback! @type, line
139
148
  end
140
149
 
141
150
  def process_stream
142
- result = IO.select([@io], nil, nil, @select_wait_time)
143
- return if result.nil? or result.empty?
144
-
145
- c = @io.read(1)
146
- return stream_error(:eof) if c.nil?
147
-
148
- @line << c
149
- process_line if c == "\n" or c == "\r"
151
+ lines = @io.gets("\r") or return stream_error(:eof)
152
+ lines.split(/\n/).each do |line|
153
+ process_line(line.chomp)
154
+ end
150
155
  end
151
-
156
+
152
157
  def run
153
158
  @thread = Thread.new do
154
159
  @alive = true
155
160
  begin
161
+ # @io.fcntl(Fcntl::F_SETFL,Fcntl::O_NONBLOCK)
156
162
  debug "start"
157
163
  process_stream while @alive
158
164
  debug "clean end!"
@@ -216,6 +222,7 @@ class MPlayer
216
222
 
217
223
  def cmdline(target = parent.opts[:path])
218
224
  cmd = "#{parent.opts[:program]} -slave "
225
+ cmd += "-wid #{parent.opts[:embed]} " if parent.opts[:embed]
219
226
  cmd += "-playlist " if target=~ /\.m3u$/
220
227
  cmd += target.to_s
221
228
  end
@@ -298,6 +305,7 @@ class MPlayer
298
305
  end
299
306
 
300
307
  def ok?
308
+ get_position
301
309
  dispatch_callbacks
302
310
  err = nil
303
311
  lock! do
@@ -322,7 +330,13 @@ class MPlayer
322
330
  @io_stdin = nil
323
331
  end
324
332
 
333
+ def get_position
334
+ send_command :get_time_pos
335
+ send_command :get_percent_pos
336
+ end
337
+
325
338
  def startup!
339
+ send_command :get_time_length
326
340
  @parent.callback! :startup
327
341
  end
328
342
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_mplayer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brent Sanders
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-09 00:00:00 -08:00
12
+ date: 2010-01-10 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency