Guest User

Untitled

a guest
May 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. import java.io.File;
  2. import scala.swing._;
  3.  
  4. import org.gstreamer.Gst;
  5. import org.gstreamer.State;
  6. import org.gstreamer.elements.PlayBin;
  7. import org.gstreamer.swing.VideoComponent;
  8. import org.gstreamer.Bus;
  9. import org.gstreamer.GstObject;
  10. import java.util.concurrent.TimeUnit;
  11. import javax.swing.Timer;
  12. import java.lang.Math;
  13. import java.awt.event._;
  14.  
  15. object VideoPlayer {
  16. def rand = (Math.random * 500).asInstanceOf[Int]
  17. def randSeek = (Math.random * 90000).asInstanceOf[Int]
  18. var t : Timer = null
  19. var playBin : PlayBin = null
  20. var rand1 = 500
  21. var rand2 = 1
  22.  
  23. def setNewTimer : Timer = {
  24. if (Math.random() < 0.2) {
  25. rand1 = rand
  26. rand2 = randSeek
  27. }
  28. new Timer(rand1, new ActionListener() {
  29. def actionPerformed(e: ActionEvent) {
  30. playBin.seek(rand2, TimeUnit.MILLISECONDS )
  31. t.stop
  32. t = setNewTimer
  33. t.start
  34. }
  35. });
  36. }
  37. def main(args : Array[String]) {
  38. val gstArgs = Gst.init("VideoPlayer", args)
  39. playBin = new PlayBin("VideoPlayer")
  40. playBin.setInputFile(new File(gstArgs(0)))
  41.  
  42. Swing.onEDT {
  43. val videoComponent = new VideoComponent;
  44. playBin.setVideoSink(videoComponent.getElement)
  45.  
  46. val panel = new BorderPanel {
  47. add(Component.wrap(videoComponent), BorderPanel.Position.Center)
  48. }
  49. val frame = new MainFrame {
  50. title = "VideoPlayer"
  51. preferredSize = new Dimension(320, 240)
  52. contents = panel
  53. open
  54. }
  55. var i = 0
  56. var count = 0;
  57. t = setNewTimer
  58. t.start
  59. playBin.setState(State.PLAYING)
  60. }
  61.  
  62. Gst.main
  63. playBin.setState(State.NULL)
  64. }
  65. }
Add Comment
Please, Sign In to add comment