use of org.fourthline.cling.support.model.TransportState in project BeyondUPnP by kevinshine.
the class NowplayingFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_nowplaying, container, false);
mTitleTextView = (TextView) view.findViewById(R.id.track_info_title);
mRelTimeText = (TextView) view.findViewById(R.id.audio_player_current_time);
mTrackDurationText = (TextView) view.findViewById(R.id.audio_player_total_time);
mPlayPauseButton = (ImageButton) view.findViewById(R.id.audio_player_play);
mPlayPauseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TransportState state = mMediaPlayerController.getCurrentState();
if (state == TransportState.PLAYING) {
PlaybackCommand.pause();
} else if (state == TransportState.PAUSED_PLAYBACK || state == TransportState.STOPPED) {
PlaybackCommand.play();
PlaybackCommand.getPositionInfo(mHandler);
}
}
});
mSeekBar = (SeekBar) view.findViewById(R.id.audio_player_seekbar);
mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
Log.i(TAG, "Start Seek");
try {
mMediaPlayerController.pauseUpdateSeekBar();
} catch (InterruptedException e) {
Log.e(TAG, "Interrupt update seekbar thread.");
}
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
float percent = (float) seekBar.getProgress() / seekBar.getMax();
int seekToSecond = (int) (mTrackDurationSeconds * percent);
Log.i(TAG, "Seek to second:" + ModelUtil.toTimeString(seekToSecond));
//Send command and receive result.
PlaybackCommand.seek(ModelUtil.toTimeString(seekToSecond), mHandler);
}
});
return view;
}
use of org.fourthline.cling.support.model.TransportState in project BeyondUPnP by kevinshine.
the class PlaybackCommand method getTransportInfo.
public static void getTransportInfo(final Handler handler) {
Device device = SystemManager.getInstance().getSelectedDevice();
//Check selected device
if (device == null)
return;
Service avtService = device.findService(SystemManager.AV_TRANSPORT_SERVICE);
if (avtService != null) {
ControlPoint cp = SystemManager.getInstance().getControlPoint();
cp.execute(new GetTransportInfo(avtService) {
@Override
public void received(ActionInvocation invocation, TransportInfo transportInfo) {
TransportState ts = transportInfo.getCurrentTransportState();
Log.i(TAG, "TransportState:" + ts.getValue());
if (TransportState.PLAYING == ts) {
handler.sendEmptyMessage(NowplayingFragment.PLAY_ACTION);
} else if (TransportState.PAUSED_PLAYBACK == ts) {
handler.sendEmptyMessage(NowplayingFragment.PAUSE_ACTION);
} else if (TransportState.STOPPED == ts) {
handler.sendEmptyMessage(NowplayingFragment.STOP_ACTION);
}
}
@Override
public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
Log.e(TAG, "GetTransportInfo failed");
}
});
}
}
Aggregations