Search in sources :

Example 1 with TransportState

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;
}
Also used : SeekBar(android.widget.SeekBar) TransportState(org.fourthline.cling.support.model.TransportState) View(android.view.View) TextView(android.widget.TextView)

Example 2 with TransportState

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");
            }
        });
    }
}
Also used : GetTransportInfo(org.fourthline.cling.support.avtransport.callback.GetTransportInfo) TransportInfo(org.fourthline.cling.support.model.TransportInfo) UpnpResponse(org.fourthline.cling.model.message.UpnpResponse) Device(org.fourthline.cling.model.meta.Device) ActionInvocation(org.fourthline.cling.model.action.ActionInvocation) Service(org.fourthline.cling.model.meta.Service) GetTransportInfo(org.fourthline.cling.support.avtransport.callback.GetTransportInfo) ControlPoint(org.fourthline.cling.controlpoint.ControlPoint) TransportState(org.fourthline.cling.support.model.TransportState)

Aggregations

TransportState (org.fourthline.cling.support.model.TransportState)2 View (android.view.View)1 SeekBar (android.widget.SeekBar)1 TextView (android.widget.TextView)1 ControlPoint (org.fourthline.cling.controlpoint.ControlPoint)1 ActionInvocation (org.fourthline.cling.model.action.ActionInvocation)1 UpnpResponse (org.fourthline.cling.model.message.UpnpResponse)1 Device (org.fourthline.cling.model.meta.Device)1 Service (org.fourthline.cling.model.meta.Service)1 GetTransportInfo (org.fourthline.cling.support.avtransport.callback.GetTransportInfo)1 TransportInfo (org.fourthline.cling.support.model.TransportInfo)1