1
2
3
4
5 package org.musicontroller.gui.components;
6
7 import org.apache.log4j.Logger;
8 import org.apache.tapestry.BaseComponent;
9 import org.apache.tapestry.IRequestCycle;
10 import org.musicontroller.DJ;
11 import org.musicontroller.core.Song;
12 import org.musicontroller.dao.Dao;
13 import org.musicontroller.security.User;
14 import org.musicontroller.streaming.StreamMaster;
15
16 public abstract class CurrentlyPlaying extends BaseComponent {
17 private static final Logger log = Logger.getLogger(CurrentlyPlaying.class);
18
19 public abstract User getUser();
20 public abstract Dao getDao();
21
22 private DJ getDJ() {
23 User user = getUser();
24 if(user==null) {
25 return null;
26 }
27 return StreamMaster.getDJByUser(user.getId());
28 }
29
30 public Song getCurrentSong() {
31 DJ dj = getDJ();
32 return dj==null ? null : dj.getCurrentSong();
33 }
34
35 public void doSkip(IRequestCycle cycle) {
36 User user = getUser();
37 if(user==null) {
38 log.debug("No user logged in, ignoring skip command.");
39 return;
40 }
41 DJ dj = StreamMaster.getDJByUser(user.getId());
42 if (dj==null) {
43 log.debug("No DJ for this user, ignoring skip command.");
44 } else {
45 dj.skipSong();
46 }
47 }
48
49 public String getTimeRemaining() {
50 DJ dj = getDJ();
51
52 Song currentSong = dj.getCurrentSong();
53 if (currentSong==null) {
54 return "";
55 } else {
56 int remaining = (currentSong.getLength()-dj.getPlayingTime());
57 return Song.getFormattedLength(remaining);
58 }
59 }
60 }