All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jmock.example.qcon.DJ Maven / Gradle / Ivy

There is a newer version: 2.13.1
Show newest version
package org.jmock.example.qcon;


public class DJ implements LocationAware, MediaTracker {
    private final MediaControl mediaControl;
    private final Playlist playlist;
    
    private String currentLocationName = null;
    private boolean trackFinished = true;
    private boolean locationChanged = false;

    
    public DJ(Playlist playlist, MediaControl mediaControl) {
        this.playlist = playlist;
        this.mediaControl = mediaControl;
    }
    
    public void locationChangedTo(String newLocationName) {
        currentLocationName = newLocationName;
        
        if (trackFinished) {
            startPlaying();
            trackFinished = false;
        }
        else {
            locationChanged = true;
        }
    }
    
    public void mediaFinished() {
        if (locationChanged) {
            startPlaying();
            locationChanged = false;
        }
        else {
            trackFinished = true;
        }
    }
    
    private void startPlaying() {
        mediaControl.play(playlist.trackFor(currentLocationName));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy