-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlaybinTest.java
More file actions
80 lines (64 loc) · 2.53 KB
/
PlaybinTest.java
File metadata and controls
80 lines (64 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package gir2java.tests;
import generated.Gst;
import generated.glib20.glib.GMainLoop;
import generated.gobject20.gobject.GObject;
import generated.gstreamer10.gst.GstBus;
import generated.gstreamer10.gst.GstBusFunc;
import generated.gstreamer10.gst.GstElement;
import generated.gstreamer10.gst.GstElementFactory;
import generated.gstreamer10.gst.GstMessage;
import generated.gstreamer10.gst.GstMessageType;
import generated.gstreamer10.gst.GstPipeline;
import generated.gstreamer10.gst.GstState;
import org.bridj.IntValuedEnum;
import org.bridj.Pointer;
public class PlaybinTest {
public static class BusWatch extends GstBusFunc {
@Override
public boolean apply(Pointer<GstBus> bus, Pointer message, Pointer user_data) {
GMainLoop loop = (GMainLoop) user_data.as(GMainLoop.class).get();
GstMessage gstMsg = (GstMessage) message.as(GstMessage.class).get();
//Can we switch on enum values in a better way?
IntValuedEnum<GstMessageType> msgType = gstMsg.gstmessage_field_type();
if (msgType.value() == GstMessageType.GST_MESSAGE_TYPE_EOS.value()) {
System.out.println("End of stream.");
loop.quit();
} else if (msgType.value() == GstMessageType.GST_MESSAGE_TYPE_ERROR.value()) {
System.out.println("Error message received on pipeline bus.");
}
return true;
}
}
public static void main(String[] args) {
Gst.init(null, null);
Pointer<GMainLoop> mainLoopPointer = GMainLoop._new(null, false).as(GMainLoop.class);
Pointer<GstElement> playbin = (Pointer<GstElement>)GstElementFactory.make(
Pointer.pointerToCString("playbin"),
Pointer.pointerToCString("the_playbin")
);
if (playbin == null) {
System.err.println("The playbin could not be created.");
return;
}
String uri = "file://" + System.getProperty("user.dir") + "/test.ogv";
System.out.println("Trying to play " + uri);
GObject.set(
playbin,
Pointer.pointerToCString("uri"),
Pointer.pointerToCString(uri),
null);
GstPipeline pipeline = playbin.as(GstPipeline.class).get();
pipeline.set_state(GstState.GST_STATE_PLAYING);
GMainLoop mainLoop = mainLoopPointer.get();
System.out.println("Everything seems OK so far, starting main loop");
GstBus bus = pipeline.get_bus().get();
BusWatch busWatch = new BusWatch();
bus.add_watch(Pointer.pointerTo(busWatch).as(GstBusFunc.class), mainLoopPointer);
bus.gstobject_unref();
mainLoop.run();
//The fun stuff happens, then:
System.out.println("Main loop finished");
pipeline.set_state(GstState.GST_STATE_NULL);
pipeline.gstobject_unref();
}
}