本文整理汇总了Java中org.bff.javampd.MPDPlayer类的典型用法代码示例。如果您正苦于以下问题:Java MPDPlayer类的具体用法?Java MPDPlayer怎么用?Java MPDPlayer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MPDPlayer类属于org.bff.javampd包,在下文中一共展示了MPDPlayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: playlist
import org.bff.javampd.MPDPlayer; //导入依赖的package包/类
/**
* Display the paginated list of playlist entries.
* @param page Current page number (starts from 0)
* @return an action result
*/
public static Result playlist(int page)
{
try
{
MPD mpd = MpdMonitor.getInstance().getMPD();
MPDPlayer player = mpd.getMPDPlayer();
Page<MPDSong> songs = Playlist.getSongs(page, 10);
return ok(playlist.render(player, songs));
}
catch (MPDException e)
{
Logger.error("MPD error", e);
flash("error", "Command failed! " + e.getMessage());
return ok(playlist.render(null, new EmptyPage<MPDSong>()));
}
}
示例2: playSong
import org.bff.javampd.MPDPlayer; //导入依赖的package包/类
/**
* Performs GET /playSong
* @return an action result
*/
public static Result playSong()
{
try
{
MPD mpd = MpdMonitor.getInstance().getMPD();
MPDPlayer player = mpd.getMPDPlayer();
PlayerStatus status = player.getStatus();
if (status == STATUS_PLAYING)
player.pause(); else
player.play();
}
catch (MPDException e)
{
Logger.error("MPD error", e);
flash("error", "Command failed! " + e.getMessage());
}
return ok("");
}
示例3: toggleRepeat
import org.bff.javampd.MPDPlayer; //导入依赖的package包/类
/**
* Performs GET /toggleRepeat
* @return an action result
*/
public static Result toggleRepeat()
{
try
{
MPD mpd = MpdMonitor.getInstance().getMPD();
MPDPlayer player = mpd.getMPDPlayer();
player.setRepeat(!player.isRepeat());
Logger.info("Setting repeat: " + player.isRepeat());
}
catch (MPDException e)
{
Logger.error("MPD error", e);
flash("error", "Command failed! " + e.getMessage());
}
return ok("");
}
示例4: toggleShuffle
import org.bff.javampd.MPDPlayer; //导入依赖的package包/类
/**
* Performs GET /toggleRandome
* @return an action result
*/
public static Result toggleShuffle()
{
try
{
MPD mpd = MpdMonitor.getInstance().getMPD();
MPDPlayer player = mpd.getMPDPlayer();
player.setRandom(!player.isRandom());
Logger.info("Setting shuffle: " + player.isRandom());
}
catch (MPDException e)
{
Logger.error("MPD error", e);
flash("error", "Command failed! " + e.getMessage());
}
return ok("");
}
示例5: toggleConsuming
import org.bff.javampd.MPDPlayer; //导入依赖的package包/类
/**
* Performs GET /toggleConsuming
* @return an action result
*/
public static Result toggleConsuming()
{
try
{
MPD mpd = MpdMonitor.getInstance().getMPD();
MPDPlayer player = mpd.getMPDPlayer();
player.setConsuming(!player.isConsuming());
Logger.info("Setting consuming: " + player.isConsuming());
}
catch (MPDException e)
{
Logger.error("MPD error", e);
flash("error", "Command failed! " + e.getMessage());
}
return ok("");
}
示例6: toggleSingleMode
import org.bff.javampd.MPDPlayer; //导入依赖的package包/类
/**
* Performs GET /toggleSingleMode
* @return an action result
*/
public static Result toggleSingleMode()
{
try
{
MPD mpd = MpdMonitor.getInstance().getMPD();
MPDPlayer player = mpd.getMPDPlayer();
player.setSingleMode(!player.isSingleMode());
Logger.info("Setting single mode: " + player.isSingleMode());
}
catch (MPDException e)
{
Logger.error("MPD error", e);
flash("error", "Command failed! " + e.getMessage());
}
return ok("");
}
示例7: nextSong
import org.bff.javampd.MPDPlayer; //导入依赖的package包/类
/**
* Performs GET /nextSong
* @return an action result
*/
public static Result nextSong()
{
try
{
MPD mpd = MpdMonitor.getInstance().getMPD();
MPDPlayer player = mpd.getMPDPlayer();
player.playNext();
}
catch (MPDException e)
{
Logger.error("MPD error", e);
flash("error", "Command failed! " + e.getMessage());
}
return ok("");
}
示例8: prevSong
import org.bff.javampd.MPDPlayer; //导入依赖的package包/类
/**
* Performs GET /prevSong
* @return an action result
*/
public static Result prevSong()
{
try
{
MPD mpd = MpdMonitor.getInstance().getMPD();
MPDPlayer player = mpd.getMPDPlayer();
player.playPrev();
}
catch (MPDException e)
{
Logger.error("MPD error", e);
flash("error", "Command failed! " + e.getMessage());
}
return ok("");
}
示例9: stopSong
import org.bff.javampd.MPDPlayer; //导入依赖的package包/类
/**
* Performs GET /stopSong
* @return an action result
*/
public static Result stopSong()
{
try
{
MPD mpd = MpdMonitor.getInstance().getMPD();
MPDPlayer player = mpd.getMPDPlayer();
player.stop();
}
catch (MPDException e)
{
Logger.error("MPD error", e);
flash("error", "Command failed! " + e.getMessage());
}
return ok("");
}
示例10: determineSongChange
import org.bff.javampd.MPDPlayer; //导入依赖的package包/类
private void determineSongChange(String playerId) {
MPD daemon = findMPDInstance(playerId);
if (daemon == null) {
// we give that player another chance -> try to reconnect
reconnect(playerId);
}
if (daemon != null) {
try {
MPDPlayer player = daemon.getMPDPlayer();
// get the song object here
MPDSong curSong = player.getCurrentSong();
MPDSong curSongCache = songInfoCache.get(playerId);
if (curSongCache != null) {
// we have some info
if (curSong.getId() != curSongCache.getId()) {
songInfoCache.put(playerId, curSong);
songChanged(playerId, curSong);
} else {
// nothing, same song
// detect play state
}
} else {
// no info about player's playback state
songInfoCache.put(playerId, curSong);
// action the song change¬ification
songChanged(playerId, curSong);
}
}
catch (MPDPlayerException pe) {
logger.error("error while updating player status: {}" + pe.getMessage(), playerId);
} catch (Exception e) {
logger.warn("Failed to communicate with '{}'", playerId);
}
}
else {
logger.warn("didn't find player configuration instance for playerId '{}'", playerId);
}
}
示例11: determineSongChange
import org.bff.javampd.MPDPlayer; //导入依赖的package包/类
private void determineSongChange(String playerId) {
MPD daemon = findMPDInstance(playerId);
if (daemon == null) {
// we give that player another chance -> try to reconnect
reconnect(playerId);
}
if (daemon != null) {
try {
MPDPlayer player = daemon.getMPDPlayer();
// get the song object here
MPDSong curSong = player.getCurrentSong();
MPDSong curSongCache = songInfoCache.get(playerId);
if (!songsEqual(curSong, curSongCache)) {
// song is different (or not in cache), update cache
songInfoCache.put(playerId, curSong);
// action the song change¬ification
songChanged(playerId, curSong);
}
} catch (MPDPlayerException pe) {
logger.error("Error while updating player status for player '{}': {}", playerId, pe.getMessage());
} catch (Exception e) {
logger.warn("Failed to communicate with player '{}'", playerId);
}
} else {
logger.warn("Player '{}' was not found or is not connected", playerId);
}
}
示例12: playlistBasicChange
import org.bff.javampd.MPDPlayer; //导入依赖的package包/类
@Override
public void playlistBasicChange(PlaylistBasicChangeEvent event)
{
try
{
MPDPlayer player = MpdMonitor.getInstance().getMPD().getMPDPlayer();
switch (event.getId())
{
case PlaylistBasicChangeEvent.SONG_ADDED:
case PlaylistBasicChangeEvent.SONG_DELETED:
sendWebsocketMessage("reload", event.getId());
break;
case PlaylistBasicChangeEvent.PLAYLIST_ENDED:
case PlaylistBasicChangeEvent.PLAYLIST_CHANGED:
// just don't care
break;
case PlaylistBasicChangeEvent.SONG_CHANGED:
sendWebsocketMessage("select", player.getCurrentSong().getPosition());
sendWebsocketMessage("songlength", player.getCurrentSong().getLength());
break;
}
}
catch (MPDException e)
{
Logger.warn("Error on event " + event.getId(), e);
}
}
示例13: executePlayerCommand
import org.bff.javampd.MPDPlayer; //导入依赖的package包/类
/**
* Executes the given <code>playerCommandLine</code> on the MPD. The
* <code>playerCommandLine</code> is split into it's properties
* <code>playerId</code> and <code>playerCommand</code>.
*
* @param playerCommandLine the complete commandLine which gets splitted into
* it's properties.
*/
private void executePlayerCommand(String playerCommandLine, Object commandParams) {
String[] commandParts = playerCommandLine.split(":");
String playerId = commandParts[0];
String playerCommand = commandParts[1];
MPD daemon = findMPDInstance(playerId);
if (daemon == null) {
// we give that player another chance -> try to reconnect
reconnect(playerId);
}
if (daemon != null) {
PlayerCommandTypeMapping pCommand = null;
try {
pCommand = PlayerCommandTypeMapping.fromString(playerCommand);
MPDPlayer player = daemon.getMPDPlayer();
switch (pCommand) {
case PAUSE: player.pause(); break;
case PLAY: player.play(); break;
case STOP: player.stop(); break;
case VOLUME_INCREASE: player.setVolume(player.getVolume() + VOLUME_CHANGE_SIZE); break;
case VOLUME_DECREASE: player.setVolume(player.getVolume() - VOLUME_CHANGE_SIZE); break;
case NEXT: player.playNext(); break;
case PREV: player.playPrev(); break;
case ENABLE:
case DISABLE:
Integer outputId = Integer.valueOf((String) commandParams);
MPDAdmin admin = daemon.getMPDAdmin();
MPDOutput output = new MPDOutput(outputId - 1); // internally mpd uses 0-based indexing
if (pCommand == PlayerCommandTypeMapping.ENABLE) {
admin.enableOutput(output);
} else {
admin.disableOutput(output);
}
break;
case VOLUME:
logger.debug("Volume adjustment received: '{}' '{}'", pCommand, commandParams);
player.setVolume(((PercentType) commandParams).intValue());
break;
}
}
catch (MPDPlayerException pe) {
logger.error("error while executing {} command: " + pe.getMessage(), pCommand);
}
catch (Exception e) {
logger.warn("unknow playerCommand '{}'", playerCommand);
}
}
else {
logger.warn("didn't find player configuration instance for playerId '{}'", playerId);
}
logger.info("executed commandLine '{}' for player '{}'", playerCommand, playerId);
}
示例14: determinePlayStateChange
import org.bff.javampd.MPDPlayer; //导入依赖的package包/类
private void determinePlayStateChange(String playerId) {
MPD daemon = findMPDInstance(playerId);
if (daemon == null) {
// we give that player another chance -> try to reconnect
reconnect(playerId);
}
if (daemon != null) {
try {
MPDPlayer player = daemon.getMPDPlayer();
// get the song object here
PlayerStatus ps = player.getStatus();
PlayerStatus curPs = playerStatusCache.get(playerId);
if (curPs != null) {
if (ps != curPs) {
logger.debug("Play state of '{}' changed", playerId);
playerStatusCache.put(playerId, ps);
PlayerCommandTypeMapping reportTo;
OnOffType reportStatus;
// trigger song update
if (ps.equals(PlayerStatus.STATUS_PAUSED) || ps.equals(PlayerStatus.STATUS_STOPPED)) {
// stopped
reportTo = PlayerCommandTypeMapping.STOP;
reportStatus = OnOffType.OFF;
} else {
// playing
reportTo = PlayerCommandTypeMapping.PLAY;
reportStatus = OnOffType.ON;
}
broadcastPlayerStateChange(playerId, reportTo, reportStatus);
} else {
// nothing, same state
}
} else {
playerStatusCache.put(playerId, ps);
}
} catch (MPDPlayerException pe) {
logger.error("error while updating player status: {}" + pe.getMessage(), playerId);
} catch (Exception e) {
logger.warn("Failed to communicate with '{}'", playerId);
}
} else {
logger.warn("didn't find player configuration instance for playerId '{}'", playerId);
}
}
示例15: determinePlayStateChange
import org.bff.javampd.MPDPlayer; //导入依赖的package包/类
private void determinePlayStateChange(String playerId) {
MPD daemon = findMPDInstance(playerId);
if (daemon == null) {
// we give that player another chance -> try to reconnect
reconnect(playerId);
}
if (daemon != null) {
try {
MPDPlayer player = daemon.getMPDPlayer();
// get the song object here
PlayerStatus ps = player.getStatus();
PlayerStatus curPs = playerStatusCache.get(playerId);
if (curPs != null) {
if (ps != curPs) {
logger.debug("Play state of player '{}' changed", playerId);
playerStatusCache.put(playerId, ps);
PlayerCommandTypeMapping reportTo;
OnOffType reportStatus;
// trigger song update
if (ps.equals(PlayerStatus.STATUS_PAUSED) || ps.equals(PlayerStatus.STATUS_STOPPED)) {
// stopped
reportTo = PlayerCommandTypeMapping.STOP;
reportStatus = OnOffType.OFF;
} else {
// playing
reportTo = PlayerCommandTypeMapping.PLAY;
reportStatus = OnOffType.ON;
}
broadcastPlayerStateChange(playerId, reportTo, reportStatus);
} else {
// nothing, same state
}
} else {
playerStatusCache.put(playerId, ps);
}
} catch (MPDPlayerException pe) {
logger.error("Error while updating player status for player '{}': {}", playerId, pe.getMessage());
} catch (Exception e) {
logger.warn("Failed to communicate with player '{}'", playerId);
}
} else {
logger.warn("Player '{}' was not found or is not connected", playerId);
}
}