StatusBarReceiver.kt 1 KB
Newer Older
konghaorui committed
1
package com.ydl.media.audio.receiver
konghaorui committed
2 3 4 5 6 7

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.text.TextUtils

konghaorui committed
8
import com.ydl.media.audio.AudioPlayer
konghaorui committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31


/**
 * Created by haorui on 2019-10-27 .
 * Des: 通知栏事件监听
 */
class StatusBarReceiver : BroadcastReceiver() {

    override fun onReceive(context: Context, intent: Intent?) {
        if (intent == null || TextUtils.isEmpty(intent.action)) {
            return
        }

        val extra = intent.getStringExtra(EXTRA)
        if (TextUtils.equals(extra, EXTRA_NEXT)) {
            AudioPlayer.get().next()
        } else if (TextUtils.equals(extra, EXTRA_PLAY_PAUSE)) {
            AudioPlayer.get().playPause()
        }
    }

    companion object {
        val ACTION_STATUS_BAR = "com.ydl.media.STATUS_BAR_ACTIONS"
32
        val ACTION_MUSIC_CLICK = "com.ydl.media.ACTION_MUSIC_CLICK"
konghaorui committed
33 34 35 36 37
        val EXTRA = "extra"
        val EXTRA_NEXT = "next"
        val EXTRA_PLAY_PAUSE = "play_pause"
    }
}