Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import scala.swing._;
- import org.gstreamer.Gst;
- import org.gstreamer.State;
- import org.gstreamer.elements.PlayBin;
- import org.gstreamer.swing.VideoComponent;
- import org.gstreamer.Bus;
- import org.gstreamer.GstObject;
- import java.util.concurrent.TimeUnit;
- import javax.swing.Timer;
- import java.lang.Math;
- import java.awt.event._;
- object VideoPlayer {
- def rand = (Math.random * 500).asInstanceOf[Int]
- def randSeek = (Math.random * 90000).asInstanceOf[Int]
- var t : Timer = null
- var playBin : PlayBin = null
- var rand1 = 500
- var rand2 = 1
- def setNewTimer : Timer = {
- if (Math.random() < 0.2) {
- rand1 = rand
- rand2 = randSeek
- }
- new Timer(rand1, new ActionListener() {
- def actionPerformed(e: ActionEvent) {
- playBin.seek(rand2, TimeUnit.MILLISECONDS )
- t.stop
- t = setNewTimer
- t.start
- }
- });
- }
- def main(args : Array[String]) {
- val gstArgs = Gst.init("VideoPlayer", args)
- playBin = new PlayBin("VideoPlayer")
- playBin.setInputFile(new File(gstArgs(0)))
- Swing.onEDT {
- val videoComponent = new VideoComponent;
- playBin.setVideoSink(videoComponent.getElement)
- val panel = new BorderPanel {
- add(Component.wrap(videoComponent), BorderPanel.Position.Center)
- }
- val frame = new MainFrame {
- title = "VideoPlayer"
- preferredSize = new Dimension(320, 240)
- contents = panel
- open
- }
- var i = 0
- var count = 0;
- t = setNewTimer
- t.start
- playBin.setState(State.PLAYING)
- }
- Gst.main
- playBin.setState(State.NULL)
- }
- }
Add Comment
Please, Sign In to add comment