@@ -42,6 +42,7 @@ const initialState = {
42
42
musicControlsActive : false ,
43
43
musicControlStatus : {
44
44
artist : "" ,
45
+ pause : true ,
45
46
} ,
46
47
} ;
47
48
@@ -126,18 +127,23 @@ export const simpleapi = {
126
127
} ,
127
128
setMusicControlsActive ( state , value ) {
128
129
state . musicControlsActive = value ;
130
+ if ( ! value ) state . musicControlStatus . artist = "" ;
129
131
} ,
130
132
setMusicControlsTitle ( state , value ) {
131
133
state . musicControlStatus . artist = value ;
132
134
} ,
135
+ setMusicControlsPuasedState ( state , value ) {
136
+ state . musicControlStatus . pause = value ;
137
+ } ,
133
138
} ,
134
139
actions : {
135
140
setPlaybackRefreshInterval ( { commit, state, dispatch, rootGetters } ) {
136
141
if ( state . playbackRefreshInterval == null ) {
137
142
state . playbackRefreshInterval = setInterval ( ( ) => {
138
143
apiInstance . get ( "/status" ) . then ( ( response ) => {
139
144
commit ( "setPlayerData" , response . data ) ;
140
- if ( rootGetters [ "settings/androidNotificationEnabled" ] === true ) {
145
+ if ( rootGetters [ "settings/androidNotificationEnabled" ] == true ) {
146
+ console . log ( "handle music controls" ) ;
141
147
dispatch ( "handleMusicControls" ) ;
142
148
}
143
149
} ) ;
@@ -150,23 +156,31 @@ export const simpleapi = {
150
156
state . playerData [ "media-title" ] || state . playerData . filename ;
151
157
152
158
if ( title != state . musicControlStatus . artist ) {
153
- console . log ( "Have to change title" ) ;
154
-
155
159
if ( state . musicControlsActive ) {
156
160
musicControls . destroy ( ) ;
157
161
musicControls . create ( { ...musicControlsSettings , track : title } ) ;
158
162
musicControls . subscribe ( musicEventHandler ) ;
159
163
musicControls . listen ( ) ;
164
+ musicControls . updateIsPlaying ( ! state . playerData . pause ) ;
160
165
} else {
161
166
musicControls . create ( { ...musicControlsSettings , track : title } ) ;
162
167
musicControls . subscribe ( musicEventHandler ) ;
163
168
musicControls . listen ( ) ;
169
+ musicControls . updateIsPlaying ( ! state . playerData . pause ) ;
164
170
}
165
171
commit ( "setMusicControlsTitle" , title ) ;
166
172
commit ( "setMusicControlsActive" , true ) ;
167
- musicControls . updateIsPlaying ( ! state . playerData . pause ) ;
173
+ /* Update isPlaying on some phones keeps sending notification to phone when it's on sleep.
174
+ So we have handle that by only updating when the the playback paused/unpaused*/
175
+ if ( state . musicControlStatus . pause != state . playerData . pause ) {
176
+ musicControls . updateIsPlaying ( ! state . playerData . pause ) ;
177
+ commit ( "setMusicControlsPuasedState" , state . playerData . pause ) ;
178
+ }
168
179
} else {
169
- musicControls . updateIsPlaying ( ! state . playerData . pause ) ;
180
+ if ( state . musicControlStatus . pause != state . playerData . pause ) {
181
+ musicControls . updateIsPlaying ( ! state . playerData . pause ) ;
182
+ commit ( "setMusicControlsPuasedState" , state . playerData . pause ) ;
183
+ }
170
184
}
171
185
} else if ( state . musicControlsActive ) {
172
186
console . log ( "Music controls should be destroyed" ) ;
0 commit comments