Search in sources :

Example 1 with PlayController

use of com.lzx.musiclibrary.control.PlayController in project MusicLibrary by lizixian18.

the class PlayerReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (TextUtils.isEmpty(action)) {
        return;
    }
    MusicService musicService = MusicService.getService();
    if (musicService == null) {
        return;
    }
    PlayControl binder = musicService.getBinder();
    if (binder == null) {
        return;
    }
    PlayController controller = binder.getController();
    if (controller == null) {
        return;
    }
    switch(action) {
        case IMediaNotification.ACTION_CLOSE:
            controller.stopMusic();
            controller.stopNotification();
            break;
        case IMediaNotification.ACTION_PLAY_PAUSE:
            if (controller.getState() == State.STATE_PLAYING) {
                controller.pauseMusic();
            } else if (controller.getState() == State.STATE_PAUSED) {
                controller.resumeMusic();
            }
            break;
        case IMediaNotification.ACTION_PREV:
            controller.playPre();
            break;
        case IMediaNotification.ACTION_NEXT:
            controller.playNext();
            break;
        default:
            break;
    }
}
Also used : MusicService(com.lzx.musiclibrary.MusicService) PlayControl(com.lzx.musiclibrary.control.PlayControl) PlayController(com.lzx.musiclibrary.control.PlayController)

Example 2 with PlayController

use of com.lzx.musiclibrary.control.PlayController in project NiceMusic by lizixian18.

the class PlayerReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (TextUtils.isEmpty(action)) {
        return;
    }
    MusicService musicService = MusicService.getService();
    if (musicService == null) {
        return;
    }
    PlayControl binder = musicService.getBinder();
    if (binder == null) {
        return;
    }
    PlayController controller = binder.getController();
    if (controller == null) {
        return;
    }
    switch(action) {
        case IMediaNotification.ACTION_CLOSE:
            controller.stopMusic();
            controller.stopNotification();
            break;
        case IMediaNotification.ACTION_PLAY_PAUSE:
            if (controller.getState() == State.STATE_PLAYING) {
                controller.pauseMusic();
            } else if (controller.getState() == State.STATE_PAUSED) {
                controller.resumeMusic();
            }
            break;
        case IMediaNotification.ACTION_PREV:
            controller.playPre();
            break;
        case IMediaNotification.ACTION_NEXT:
            controller.playNext();
            break;
        default:
            break;
    }
}
Also used : MusicService(com.lzx.musiclibrary.MusicService) PlayControl(com.lzx.musiclibrary.control.PlayControl) PlayController(com.lzx.musiclibrary.control.PlayController)

Aggregations

MusicService (com.lzx.musiclibrary.MusicService)2 PlayControl (com.lzx.musiclibrary.control.PlayControl)2 PlayController (com.lzx.musiclibrary.control.PlayController)2