I'm using VLCj on Java 7 to try and record some Internet radio streams. I'm currently using a HeadlessMediaPlayer within a larger program to schedule recordings at the correct time, ending with the TimeReachedCondition as seen below. However, I can't seem to get any meaningful results from it. Sometimes the stream seems to be recorded correctly (though seemingly never for the correct amount of time), but often the output file will grow far and away beyond the size expected from a recording of the size requested, with this file not displaying any relevance to the data being broadcast. This used to be accompanied by a `queue input backward in time' error on older versions of VLC, but with the latest iteration this seems to have disappeared. Could anyone possibly shed some light on why this could be happening?
For clarity's sake, another class will call the method shown below when a certain time is reached. The player should then capture the stream until the time condition is reached, at which point it's paused and stopped as below. I've tried this in a number of configurations - this particular one uses a Thread local to the class to control the starting and stopping, but I've tried building a very rudimentary event-driven system, splitting the below into play and stop to control this as well and I'm finding the same results.
Also, I've tried this on both on my personal development laptop which is OSX and a server via ssh running Red Hat.
Sorry for the essay
Ninja edit: Example of a link I'm trying to stream: http://ic.8a2629d7.0492e3.as-hls-ww-liv ... 48000.m3u8
Code: Select all
final long period = new Duration(startTime, endTime).getMillis();
System.out.println("Recording length: " + period + "ms");
MediaPlayerFactory mFactory = new MediaPlayerFactory();
MediaPlayer player = mFactory.newHeadlessMediaPlayer();
final String options = "sout=" +
"#transcode{acodec=mp3,ab=128,channels=1,samplerate=44100}" +
":std{access=file,mux=raw," + "dst="
+ recording.getFile().getAbsolutePath() + "}";
try {
long time = period;
Condition<?> playingCondition = new PlayingCondition(player) {
@Override
protected void onBefore() {
mediaPlayer.startMedia(streamLocation, options);
}
};
playingCondition.await();
System.out.println("Started at " + DateTime.now().toString());
Condition<?> timeReachedCondition =
new TimeReachedCondition(player, time) {
@Override
protected void onBefore() {
mediaPlayer.setTime(targetTime);
}
};
timeReachedCondition.await();
Condition<?> pausedCondition = new PausedCondition(player) {
@Override
protected void onBefore() {
mediaPlayer.pause();
}
};
pausedCondition.await();
System.out.println("Stopped at " + DateTime.now().toString());
player.stop();
}
catch (UnexpectedErrorConditionException e) {
System.out.println("ERROR!");
} catch (UnexpectedFinishedConditionException e) {
System.out.println("FINISHED!");
} catch (InterruptedException e) {
System.out.println("INTERRUPTED!");
}
}