#!/usr/bin/env ruby frame = '' music = "hoge.mp3" t = Thread.new do # child process p "Child playing #{music} file." require 'open3' command = "mpg123 -v #{music}" i, o, e = *Open3.popen3(command) while not e.closed? line = "" while l = e.getc if l != ?\r line << l.chr else # STDERR.print line+"\r" break end end if /Frame\#\s*(\d+)/ =~ line STDERR.printf "%s ", $1 if $DEBUG frame = $1.to_i end end end while true STDERR.print "cmd(q¤Ç½ªÎ»): " a = gets if a.nil? || /q/ =~ a Thread.kill t break end end printf "Stopping at frame %d\n", frame