I developed this software
http://sourceforge.net/projects/cover/
I use VLCJ for playing video and make automatically snapshots.
The snapshots are use to resume a video for example take snapshot every 20 seconds during all the video (like thumbnails).
Actually, I have a working code, but it is not satisfactory at all.
I have a problem, I can not know if VLC has move the video in the right position. I use « mediaPlayer.setTime(time) » to move the player to the right frame. After that I have to wait than VLC moves to the right position, but this time change with the type of video format, codec, size of the video.
There is the method « getTime() », but even if the video has not move to the right position, it send me the same position I put with setTime(time).
Another problem is the time the file takes to be written on the disk. I use the same trick and wait generally one second.
The only code I found about the snapshot is this one http://wiki.videolan.org/LibVLC_SampleCode_Thumbnailer
Thanks you for your help
This is a part of the concerning source code:
Code: Select all
/**
* Make a all the snapShot from the time list
*/
private void makeAllSnapShot() {
// "There is a race condition in native libraries when starting up, so
// do not play immediately - empirically the most reliable way to avoid
// a native library crash is to sleep for a bit. Not ideal, if you find
// a better way let me know"
// I play the media during 5 seconds to be sure it is corretly loaded
// I put my treatement in pause
long debut = System.currentTimeMillis();
long fin = debut + 5000;
while (System.currentTimeMillis() < fin) {
}
// we put the player in pause
mediaPlayer.pause();
updateIsPlaying(false);
debut = System.currentTimeMillis();
fin = debut + 1000;
while (System.currentTimeMillis() < fin) {
}
// we can make the list only when the video is load
// its is a list of times (the player gos to each time and makes a snapshot
makeTimeList();
for (int i = 0; i < timeList.size(); i++) {
// We say to the player to go to the time store in the list
Long currenttime = timeList.get(i);
mediaPlayer.setTime(currenttime);
// we need to wait for the internal update of the vlclib
// waitMoveInt : this information is given by the user
debut = System.currentTimeMillis();
fin = debut + waitMoveInt;
while (System.currentTimeMillis() < fin) {
}
makeSnapShot();
// wait to be sure the file is finished to write on the disk
// waitWriteInt : this information is given by the user
debut = System.currentTimeMillis();
fin = debut + waitWriteInt;
while (System.currentTimeMillis() < fin) {
}
}
}
/**
* Make a SnapShot to the current frame The video need to be put in pause
*/
private void makeSnapShot() {
if (isPlaying == false) {
// code.......
File filePathSnapshot = new File(stgPathSnapshot);
mediaPlayer.saveSnapshot(filePathSnapshot);
// code .....
}
}