-
-
Notifications
You must be signed in to change notification settings - Fork 110
/
JcPlayerNotificationReceiver.kt
executable file
·57 lines (47 loc) · 1.87 KB
/
JcPlayerNotificationReceiver.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.example.jean.jcplayer.service.notification
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.example.jean.jcplayer.JcPlayerManager
import com.example.jean.jcplayer.general.errors.AudioListNullPointerException
class JcPlayerNotificationReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val jcPlayerManager = JcPlayerManager.getInstance(context)
var action = ""
if (intent.hasExtra(JcNotificationPlayer.ACTION)) {
action = intent.getStringExtra(JcNotificationPlayer.ACTION)
}
when (action) {
JcNotificationPlayer.PLAY -> try {
jcPlayerManager.get()?.continueAudio()
jcPlayerManager.get()?.updateNotification()
} catch (e: Exception) {
e.printStackTrace()
}
JcNotificationPlayer.PAUSE -> try {
jcPlayerManager.get()?.pauseAudio()
jcPlayerManager.get()?.updateNotification()
} catch (e: Exception) {
e.printStackTrace()
}
JcNotificationPlayer.NEXT -> try {
jcPlayerManager.get()?.nextAudio()
} catch (e: AudioListNullPointerException) {
try {
jcPlayerManager.get()?.continueAudio()
} catch (e1: AudioListNullPointerException) {
e1.printStackTrace()
}
}
JcNotificationPlayer.PREVIOUS -> try {
jcPlayerManager.get()?.previousAudio()
} catch (e: Exception) {
try {
jcPlayerManager.get()?.continueAudio()
} catch (e1: AudioListNullPointerException) {
e1.printStackTrace()
}
}
}
}
}