-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAudioPlayerTutorial.txt
More file actions
53 lines (36 loc) · 1.85 KB
/
Copy pathAudioPlayerTutorial.txt
File metadata and controls
53 lines (36 loc) · 1.85 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
Now for a real application - playing audio files.
Since putting together pipelines is tedious, boring and somewhat error-prone
for newcomers to gstreamer, there are already pre-fabricated Pipelines that
do it all for you, such as a PlayBin.
So, we will be lazy and use a PlayBin to build our AudioPlayer.
public class AudioPlayer {
public static void main(String[] args) {
args = Gst.init("AudioPlayer", args);
PlayBin playbin = new PlayBin("AudioPlayer");
playbin.setInputFile(new File(args[0]));
playbin.setVideoSink(ElementFactory.make("fakesink", "videosink"));
playbin.setState(State.PLAYING);
Gst.main();
playbin.setState(State.NULL);
}
}
You've already seen this line in the SimplePipelineTutorial:
args = Gst.init("AudioPlayer", args);
Next we created a PlayBin instead of a basic Pipeline:
PlayBin playbin = new PlayBin("AudioPlayer");
A PlayBin is just a special Pipeline, so all Pipeline methods work on it just
as they would on a normal Pipeline.
The PlayBin needs to know what file you want it to play, so tell it via:
playbin.setInputFile(new File(args[0]));
You can use playbin.setURI() instead when playing a file from a URL.
By default, if the PlayBin detects video in the file being played, it will open
a window to display the video - we don't want that, so we use our friend the
fakesink to turn off that ability by throwing away the video data.
playbin.setVideoSink(ElementFactory.make("fakesink", "videosink"));
After the PlayBin is set up, we set it playing, and cleanup after it finishes.
playbin.setState(State.PLAYING);
Gst.main();
playbin.setState(State.NULL);
You will recognise the above lines from the SimplePipelineTutorial.
Note: The AudioPlayer does not exit - we will address how to detect this in
another tutorial.