Created
July 12, 2010 23:13
-
-
Save hakobe/473210 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment