Dobry den,
potreboval by som poradit ohladom syncronizacie vlakien.
class VideoPlayer implements Runnable {
// premenne a nejaky kod
public void run() {
player.pause();
// podmienky pre spustenie (kliknutie na play)
while (player.getState() != org.gstreamer.State.NULL) {
synchronized (videoPlayerThread) {
try {
do {
System.out.println("VP caka na notify()");
videoPlayerThread.wait();
System.out.println("Stav sa zmenil: " + changed);
} while (!changed);
changed = false;
} catch (InterruptedException e) {
player.setState(org.gstreamer.State.NULL);
stopPlayer();
}
}
if (player.getState() == org.gstreamer.State.PLAYING) {
player.pause();
} else {
player.play();
}
System.out.println("Stav prehravaca: " + player.getState());
}
}
public void playpause() {
synchronized (videoPlayerThread) {
changed = true;
videoPlayerThread.notify();
}
}
// Dalsi blok nezauimaveho kodu ktory zabezpeci napr. aby sa video po prehrati prehralo znova
}
Metodu playpause() volam napr. stalcenim talcika. Dva krat za sebou sa mi dokaze zmenit stav, teda pause()->play()->pause(). Tam to vacsinou skonci a cela aplikacia zamrzne, ale neuziva ziadne systemove prostriedky.