Class: Shoes::Video
Constant Summary collapse
- JFile =
java.io.File
- BufferSize =
4096
Instance Method Summary collapse
- #decode_input_stream(audio_format, audio_input_stream) ⇒ Object
- #getLine(audioFormat) ⇒ Object
-
#initialize(args) ⇒ Video
constructor
A new instance of Video.
- #play ⇒ Object
- #rawplay(decoded_audio_format, decoded_audio_input_stream) ⇒ Object
Constructor Details
Instance Method Details
#decode_input_stream(audio_format, audio_input_stream) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/plugins/video.rb', line 39 def decode_input_stream audio_format, audio_input_stream case audio_format.encoding when Java::JavazoomSpiVorbisSampledFile::VorbisEncoding, Java::JavazoomSpiMpegSampledFile::MpegEncoding decoded_format = AudioFormat.new(AudioFormat::Encoding::PCM_SIGNED, audio_format.getSampleRate(), 16, audio_format.getChannels(), audio_format.getChannels() * 2, audio_format.getSampleRate(), false) decoded_audio_input_stream = AudioSystem.getAudioInputStream(decoded_format, audio_input_stream) return decoded_format, decoded_audio_input_stream else return audio_format, audio_input_stream end end |
#getLine(audioFormat) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/plugins/video.rb', line 70 def getLine(audioFormat) res = nil info = DataLine::Info.new(SourceDataLine.java_class, audioFormat) res = AudioSystem.getLine(info) res.open(audioFormat) res end |
#play ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/plugins/video.rb', line 30 def play Thread.new do audio_input_stream = AudioSystem.getAudioInputStream JFile.new(@path) audio_format = audio_input_stream.getFormat rawplay *decode_input_stream(audio_format, audio_input_stream) audio_input_stream.close end end |
#rawplay(decoded_audio_format, decoded_audio_input_stream) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/plugins/video.rb', line 51 def rawplay(decoded_audio_format, decoded_audio_input_stream) sampled_data = Java::byte[BufferSize].new line = getLine(decoded_audio_format) if line != nil line.start() bytes_read = 0, bytes_written = 0 while bytes_read != -1 bytes_read = decoded_audio_input_stream.read(sampled_data, 0, sampled_data.length) if bytes_read != -1 bytes_written = line.write(sampled_data, 0, bytes_read) end end line.drain() line.stop() line.close() decoded_audio_input_stream.close() end end |