Skip to content

Commit

Permalink
Merge pull request #7 from eluchsinger/media-player-enhancement
Browse files Browse the repository at this point in the history
Media player enhancement
  • Loading branch information
eluchsinger committed Apr 24, 2016
2 parents 52638f3 + 58c98c9 commit 8660b23
Show file tree
Hide file tree
Showing 71 changed files with 1,311 additions and 310 deletions.
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#Idea Projects
**/.idea/workspace.xml
**/.idea/dictionaries/eluch.xml
**/.idea/tasks.xml
**/.idea
**/.idea/modules
**/.idea/libraries
**/.idea/compiler.xml
**/.idea/gradle.xml
**/.idea/misc.xml
**/.idea/modules.xml
**/.idea/vcs.xml
**/.idea/uiDesigner.xml

#WirelessSoundSystem.iml

# Windows image file caches
Expand All @@ -11,6 +20,7 @@ ehthumbs.db
# Folder config file
Desktop.ini


# Recycle Bin used on file shares
$RECYCLE.BIN/

Expand Down
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/dictionaries/Esteban.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/file.template.settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/fileTemplates/includes/File Header.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ plugins {

repositories {
jcenter()

flatDir {
dirs 'resources/libs'
}
}

mainClassName = "controllers.MainApp"
version = 0.2

mainClassName = "controllers.MainApp"

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
compile files('resources/libs/jl1.0.1.jar')
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.+'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.+'
compile project (':shared')
Expand Down
2 changes: 1 addition & 1 deletion Client/src/main/java/controllers/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void start(Stage primaryStage) throws Exception{

FXMLLoader loader = new FXMLLoader(getClass().getResource("/views/ClientWindow.fxml"));
Parent root = loader.load();

// Add Stage object to the client window view model.
Object o = loader.getController();
if(ClientWindowViewModel.class == o.getClass()){
Expand Down
6 changes: 5 additions & 1 deletion Client/src/main/java/controllers/io/cache/CacheService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import java.io.IOException;

/**
* <pre>
* Created by Esteban Luchsinger on 15.03.2016.
* The Cache Service provides an interface to cache data into whatever kind of
* cache is needed.
* </pre>
*/
public interface CacheService {

Expand All @@ -17,10 +19,12 @@ public interface CacheService {
void writeData(byte[] data) throws IOException;

/**
* <pre>
* Resets the cache.
* All data currently cached is lost.
*
* (Depending on the cache, may be good to use before closing the application)
* (Depending on the cache, this might be required to use before closing the application)
* </pre>
*/
void reset();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import java.nio.channels.OverlappingFileLockException;

/**
* <pre>
* Created by Esteban Luchsinger on 15.12.2015.
* This class handles the handling of the cache that can grow and shrink dynamically.
* </pre>
*/
public class DynamicFileCacheService implements FileCacheService {
private final Logger logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import java.net.URI;

/**
* <pre>
* Created by Esteban Luchsinger on 16.03.2016.
* The File Cache Service provides an interface to write and read
* cache data in a file based cache.
* </pre>
*/
public interface FileCacheService extends CacheService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* <pre>
* Created by Esteban Luchsinger on 16.03.2016.
* The static cache service uses an immutable cache.
* The cache can only be written once. If the cache is already used, and writeData
* is called again, it overwrites all the data.
* </pre>
*/
public class StaticFileCacheService implements FileCacheService {
private final Logger logger;
Expand All @@ -21,6 +24,12 @@ public class StaticFileCacheService implements FileCacheService {

private File rootFile = null;

/**
* Workaround: This field marks the cache as "USED".
* This is a workaround for the MediaPlayer to detect, if the song was already played.
*/
private final AtomicBoolean cacheWasUsed = new AtomicBoolean();

/**
* Default constructor
* @throws IOException
Expand All @@ -31,7 +40,6 @@ public StaticFileCacheService() throws IOException {
String tempDir = System.getProperty("java.io.tmpdir");

this.rootFile = File.createTempFile(FILE_PREFIX, FILE_SUFFIX, new File(tempDir));

}

/**
Expand Down Expand Up @@ -111,7 +119,6 @@ private File createFile() throws IOException {
/**
* Returns the new file and if it doesn't exist, it creates a new file.
* @return Returns the cache file.
* @throws IOException
*/
public File getFile() {
try {
Expand Down Expand Up @@ -140,4 +147,12 @@ public String getAbsoluteFilePath() {
public URI getFileURI() {
return this.rootFile.toURI();
}

public void setCacheUsed() {
this.cacheWasUsed.set(true);
}

public boolean isCacheUsed() {
return this.cacheWasUsed.get();
}
}
41 changes: 41 additions & 0 deletions Client/src/main/java/controllers/media/CachedMediaPlayer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package controllers.media;

import controllers.io.cache.CacheService;
import models.songs.Song;

/**
* <pre>
* Created by Esteban Luchsinger on 24.04.2016.
* This <code>MediaPlayer</code> uses a cache as a source for the Media.
* </pre>
*/
public class CachedMediaPlayer {

private final CacheService cacheService;

public CachedMediaPlayer(CacheService cacheService) {
this.cacheService = cacheService;
}

/**
* Plays a song.
* If this song is already cached, it plays it from the cache.
* If the song is not yet cached, it will cache it first.
* @param song
*/
public void play(Song song) {

}

/**
* Pauses the current MediaPlayer from playing a song.
*/
public void pause() {

}

public void stop() {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
import java.util.concurrent.Executors;

/**
* <pre>
* Created by Esteban Luchsinger on 08.12.2015.
* This is the ClientDiscoveryService of the Client.
* </pre>
*/
public class ClientDiscoveryService implements Closeable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import models.clients.Server;

/**
* <pre>
* Created by Esteban Luchsinger on 02.03.2016.
* OnServerConnected interface.
* This event is called when a server connects.
* </pre>
*/
@FunctionalInterface
public interface OnServerConnected {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import models.clients.Server;

/**
* <pre>
* Created by Esteban Luchsinger on 02.03.2016.
* Called when a server disconnects.
* </pre>
*/
@FunctionalInterface
public interface OnServerDisconnected {
void serverDisconnected(Server server);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package controllers.networking.streaming.music;

import controllers.io.cache.file.FileCacheService;
import controllers.networking.streaming.music.callback.OnMusicStreamingStatusChanged;
import controllers.networking.streaming.music.callback.OnPlay;
import controllers.networking.streaming.music.callback.OnRename;
import controllers.networking.streaming.music.callback.OnStop;
import controllers.networking.streaming.music.callback.*;
import models.clients.Server;

/**
* <pre>
* Created by Esteban Luchsinger on 01.03.2016.
* Interface provides all needed public methods.
* </pre>
*/
public interface MusicStreamingService {

Expand All @@ -35,6 +34,9 @@ public interface MusicStreamingService {
void addOnPlayListener(OnPlay listener);
void removeOnPlayListener(OnPlay listener);

void addOnPauseListener(OnPause listener);
void removeOnPauseListener(OnPause listener);

void addOnStopListener(OnStop listener);
void removeOnStopListener(OnStop listener);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package controllers.networking.streaming.music;

/**
* <pre>
* Created by Esteban Luchsinger on 29.02.2016.
* Enumerates the service status.
* </pre>
*/
public enum ServiceStatus {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import controllers.networking.streaming.music.ServiceStatus;

/**
* <pre>
* Created by Esteban Luchsinger on 29.02.2016.
* Functional Interface
* </pre>
*/
@FunctionalInterface
public interface OnMusicStreamingStatusChanged {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package controllers.networking.streaming.music.callback;

/**
* <pre>
* Created by Esteban on 22.04.2016.
* Tells that the song should be paused.
* </pre>
*/
@FunctionalInterface
public interface OnPause {
void pause();
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package controllers.networking.streaming.music.callback;

import models.networking.dtos.PlayCommand;

/**
* <pre>
* Created by Esteban Luchsinger on 17.03.2016.
* Tells that the song should be played.
* </pre>
*/
@FunctionalInterface
public interface OnPlay {
Expand Down
Loading

0 comments on commit 8660b23

Please sign in to comment.