Permalink
Browse files

Implemented commands "broadcast", "skip", "stop" and "start"

  • Loading branch information...
1 parent 869322d commit 8a46cd7984202e5e22041f0a70254ca231dd40b8 @Jackstrom Jackstrom committed May 19, 2012
Showing with 112 additions and 17 deletions.
  1. +13 −1 src/ContentManager.java
  2. +3 −0 src/PlayMode.java
  3. +24 −5 src/Player.java
  4. +72 −11 src/main.java
View
14 src/ContentManager.java
@@ -57,7 +57,19 @@ public boolean rescan() {
return true;
}
- public String getNext() {
+ public String getNext(PlayMode mode) {
+ if(mode == PlayMode.Music) {
+ synchronized(contentLock) {
+ if(songNr >= music.size()) {
+ songNr = 0;
+ music.shuffle();
+ }
+ //Play song
+ type = music.getType(songNr);
+ return music.getFile(songNr++);
+ }
+ }
+
//Check programs
synchronized(watcherLock) {
if(watcher != null) {
View
3 src/PlayMode.java
@@ -0,0 +1,3 @@
+public enum PlayMode {
+ Default, Music
+}
View
29 src/Player.java
@@ -25,7 +25,10 @@
private volatile String logDir;
private PlayBin2 playbin;
private String artist, album, title, length, type;
+ private boolean halt = false;
private boolean quit = false;
+ public PlayMode mode = PlayMode.Default;
+
public Shotgun shotgun = new Shotgun();
public Player() throws FileNotFoundException, IOException {
@@ -46,6 +49,25 @@ public Player() throws FileNotFoundException, IOException {
bus.connect((Bus.TAG)this);
}
+ public void skip() {
+ interrupt();
+ }
+
+ public void pause() {
+ halt = true;
+ }
+
+ public void play() {
+ halt = false;
+ }
+
+ public void setMetadata(String artist, String title, String album) {
+ this.artist = artist;
+ this.title = title;
+ this.album = album;
+ updateMetadata();
+ }
+
public boolean rescan() {
try {
parser.reload();
@@ -64,8 +86,9 @@ public boolean rescan() {
public void run() {
// Playloop
while(!quit) {
+ while(halt);
Gst.init("BusMessages", new String[]{});
- playbin.setInputFile(new File(content.getNext()));
+ playbin.setInputFile(new File(content.getNext(mode)));
type = content.getType();
playbin.setState(org.gstreamer.State.PLAYING);
Gst.main();
@@ -80,10 +103,6 @@ public void quit() {
Gst.quit();
content.close();
}
-
- public void playOnceAt() {
-
- }
@Override
public void endOfStream(GstObject source) {
View
83 src/main.java
@@ -25,23 +25,14 @@
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;
public class main {
-
- // init counters for playlist managment
- static int PlayCount = 0;
- static int PromoCount = 0;
- static int Promo = 0;
- static ArrayList<MetadataServer> mdServers;
-
- public static String artist, album, title, length, type;
+ static Player player = null;
public static void main(String[] args) {
- Player player = null;
try {
player = new Player();
} catch(IOException ex) {
@@ -57,6 +48,7 @@ public static void main(String[] args) {
*
* help
* rescan
+ * broadcast
* start
* stop (soft)
* skip
@@ -80,14 +72,83 @@ else if(command[0].equalsIgnoreCase("rescan")) {
else if(command[0].equalsIgnoreCase("quit")) {
break;
}
+ else if(command[0].equalsIgnoreCase("broadcast"))
+ broadcastLoop();
+ else if(command[0].equalsIgnoreCase("skip"))
+ player.skip();
+ else if(command[0].equalsIgnoreCase("stop")) {
+ if(command.length < 2) {
+ System.out.println("soft/hard specification required");
+ }
+ else if(command[1].equalsIgnoreCase("soft")) {
+ System.out.println("Stopping after current song");
+ player.pause();
+ }
+ else if(command[1].equalsIgnoreCase("hard")) {
+ System.out.println("Hard stop");
+ player.pause();
+ player.interrupt();
+ }
+ else
+ System.out.println("Invalid command use \"soft\" or \"hard\"");
+ }
+ else if(command[0].equalsIgnoreCase("start")) {
+ player.play();
+ System.out.println("Player started");
+ }
}
player.shotgun.fire();
}
+ public static void broadcastLoop() {
+ Scanner scan = new Scanner(System.in);
+ String command = "";
+ System.out.println("***Entering boradcast mode***");
+ System.out.print("Artist (Narvik Studentradio): ");
+ command = scan.nextLine();
+ if(command.equals(""))
+ command = "Narvik Studentradio";
+ String artist = command;
+ System.out.println("Title (Mandagssendingen): ");
+ command = scan.nextLine();
+ if(command.equals(""))
+ command = "Mandagssendingen";
+ String title = command;
+ System.out.println("Album (Live): ");
+ command = scan.nextLine();
+ if(command.equals(""))
+ command = "Live";
+ String album = command;
+ System.out.println("***Starting broadcast***");
+
+ while(true) {
+ player.pause();
+ player.setMetadata(artist, title, album);
+ System.out.println("\r***Player stopped, metadata set, any command for music break, \"q\" to exit***");
+ command = scan.nextLine();
+ if(command.equalsIgnoreCase("q")) {
+ System.out.println("\r***Broadcast ended, normal play will resume***");
+ break;
+ }
+ else {
+ player.mode = PlayMode.Music;
+ player.play();
+ System.out.println("\r***Music break started, any command to end on current song***");
+ command = scan.nextLine();
+ player.mode = PlayMode.Default;
+ }
+ }
+ player.play();
+ }
+
public static void printHelp() {
System.out.println("List of commands:");
System.out.println("rescan - rescan properties file and content folders");
- System.out.println("quit - stop stuff");
+ System.out.println("broadcast - enter broadcast mode");
+ System.out.println("skip - skip to next song, not advisable");
+ System.out.println("stop soft/hard - stop the player, after current song or immedeately");
+ System.out.println("start - start player after it has been stopped");
+ System.out.println("quit - kill everything");
}
public static String getDateTime() {

0 comments on commit 8a46cd7

Please sign in to comment.