Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java
Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Line(s) | 76 | public void onServiceStart(BackgroundService service) { | |||
---|---|---|---|---|---|
83 | } | 83 | } | ||
84 | 84 | | |||
85 | mpris.setPlayerStatusUpdatedHandler("activity", new Handler() { | 85 | mpris.setPlayerStatusUpdatedHandler("activity", new Handler() { | ||
86 | @Override | 86 | @Override | ||
87 | public void handleMessage(Message msg) { | 87 | public void handleMessage(Message msg) { | ||
88 | runOnUiThread(new Runnable() { | 88 | runOnUiThread(new Runnable() { | ||
89 | @Override | 89 | @Override | ||
90 | public void run() { | 90 | public void run() { | ||
91 | String song = mpris.getCurrentSong(); | 91 | updatePlayerStatus(mpris); | ||
92 | | ||||
93 | TextView nowPlaying = (TextView) findViewById(R.id.now_playing_textview); | | |||
94 | if (!nowPlaying.getText().toString().equals(song)) { | | |||
95 | nowPlaying.setText(song); | | |||
96 | } | | |||
97 | | ||||
98 | //Hacks for Spotify because it reports incorrect info about what it supports | | |||
99 | boolean isSpotify = "spotify".equals(mpris.getPlayer().toLowerCase()); | | |||
100 | | ||||
101 | if (mpris.getLength() > -1 && mpris.getPosition() > -1 && !isSpotify) { | | |||
102 | ((TextView) findViewById(R.id.time_textview)).setText(milisToProgress(mpris.getLength())); | | |||
103 | SeekBar positionSeek = (SeekBar)findViewById(R.id.positionSeek); | | |||
104 | positionSeek.setMax((int)(mpris.getLength())); | | |||
105 | positionSeek.setProgress((int)(mpris.getPosition())); | | |||
106 | findViewById(R.id.progress_slider).setVisibility(View.VISIBLE); | | |||
107 | } else { | | |||
108 | findViewById(R.id.progress_slider).setVisibility(View.GONE); | | |||
109 | } | | |||
110 | | ||||
111 | int volume = mpris.getVolume(); | | |||
112 | ((SeekBar) findViewById(R.id.volume_seek)).setProgress(volume); | | |||
113 | | ||||
114 | boolean isPlaying = mpris.isPlaying(); | | |||
115 | if (isPlaying) { | | |||
116 | ((ImageButton) findViewById(R.id.play_button)).setImageResource(android.R.drawable.ic_media_pause); | | |||
117 | findViewById(R.id.play_button).setVisibility(mpris.isPauseAllowed() ? View.VISIBLE : View.GONE); | | |||
118 | } else { | | |||
119 | ((ImageButton) findViewById(R.id.play_button)).setImageResource(android.R.drawable.ic_media_play); | | |||
120 | findViewById(R.id.play_button).setVisibility(mpris.isPlayAllowed() ? View.VISIBLE : View.GONE); | | |||
121 | } | | |||
122 | | ||||
123 | if (isSpotify) { | | |||
124 | findViewById(R.id.volume_layout).setVisibility(View.INVISIBLE); | | |||
125 | findViewById(R.id.rew_button).setVisibility(View.GONE); | | |||
126 | findViewById(R.id.ff_button).setVisibility(View.GONE); | | |||
127 | } else { | | |||
128 | findViewById(R.id.volume_layout).setVisibility(View.VISIBLE); | | |||
129 | findViewById(R.id.rew_button).setVisibility(mpris.isSeekAllowed() ? View.VISIBLE : View.GONE); | | |||
130 | findViewById(R.id.ff_button).setVisibility(mpris.isSeekAllowed() ? View.VISIBLE : View.GONE); | | |||
131 | } | | |||
132 | findViewById(R.id.next_button).setVisibility(mpris.isGoNextAllowed() ? View.VISIBLE : View.GONE); | | |||
133 | findViewById(R.id.prev_button).setVisibility(mpris.isGoPreviousAllowed() ? View.VISIBLE : View.GONE); | | |||
134 | } | 92 | } | ||
135 | }); | 93 | }); | ||
136 | } | 94 | } | ||
137 | }); | 95 | }); | ||
138 | 96 | | |||
139 | mpris.setPlayerListUpdatedHandler("activity", new Handler() { | 97 | mpris.setPlayerListUpdatedHandler("activity", new Handler() { | ||
140 | @Override | 98 | @Override | ||
141 | public void handleMessage(Message msg) { | 99 | public void handleMessage(Message msg) { | ||
Show All 22 Lines | 109 | public void run() { | |||
164 | 122 | | |||
165 | spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | 123 | spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | ||
166 | @Override | 124 | @Override | ||
167 | public void onItemSelected(AdapterView<?> arg0, View arg1, int pos, long id) { | 125 | public void onItemSelected(AdapterView<?> arg0, View arg1, int pos, long id) { | ||
168 | 126 | | |||
169 | if (pos >= playerList.size()) return; | 127 | if (pos >= playerList.size()) return; | ||
170 | 128 | | |||
171 | String player = playerList.get(pos); | 129 | String player = playerList.get(pos); | ||
172 | if (player.equals(mpris.getPlayer())) { | 130 | if (player.equals(targetPlayer)) { | ||
173 | return; //Player hasn't actually changed | 131 | return; //Player hasn't actually changed | ||
174 | } | 132 | } | ||
175 | mpris.setPlayer(player); | 133 | targetPlayer = player; | ||
176 | 134 | updatePlayerStatus(mpris); | |||
177 | //Clear values from previous player | | |||
178 | ((TextView) findViewById(R.id.now_playing_textview)).setText(""); | | |||
179 | ((TextView) findViewById(R.id.time_textview)).setText(milisToProgress(0)); | | |||
180 | ((SeekBar)findViewById(R.id.positionSeek)).setMax(0); | | |||
181 | } | 135 | } | ||
182 | 136 | | |||
183 | @Override | 137 | @Override | ||
184 | public void onNothingSelected(AdapterView<?> arg0) { | 138 | public void onNothingSelected(AdapterView<?> arg0) { | ||
185 | mpris.setPlayer(null); | 139 | targetPlayer = null; | ||
186 | } | 140 | } | ||
187 | }); | 141 | }); | ||
188 | 142 | | |||
189 | if (targetPlayer != null) { | 143 | if (targetPlayer != null) { | ||
190 | int targetIndex = adapter.getPosition(targetPlayer); | 144 | int targetIndex = adapter.getPosition(targetPlayer); | ||
191 | if (targetIndex >= 0) { | 145 | if (targetIndex >= 0) { | ||
192 | spinner.setSelection(targetIndex); | 146 | spinner.setSelection(targetIndex); | ||
193 | } | 147 | } | ||
194 | targetPlayer = null; | 148 | targetPlayer = null; | ||
149 | } | ||||
150 | String selectedPlayer; | ||||
151 | if (spinner.getSelectedItemPosition() >= 0) { | ||||
152 | selectedPlayer = playerList.get(spinner.getSelectedItemPosition()); | ||||
195 | } else { | 153 | } else { | ||
196 | // restore last selected player | 154 | selectedPlayer = null; | ||
197 | int position = adapter.getPosition(mpris.getPlayer()); | | |||
198 | if (position >= 0) { | | |||
199 | spinner.setSelection(position); | | |||
200 | } | 155 | } | ||
156 | if ((targetPlayer == null && selectedPlayer != null) || (targetPlayer != null && !targetPlayer.equals(selectedPlayer))) { | ||||
thomasp: `targetPlayer` is always `null` here. Please simplify beginning from line 143. | |||||
157 | targetPlayer = selectedPlayer; | ||||
158 | updatePlayerStatus(mpris); | ||||
201 | } | 159 | } | ||
202 | } | 160 | } | ||
203 | }); | 161 | }); | ||
204 | } | 162 | } | ||
205 | }); | 163 | }); | ||
206 | 164 | | |||
207 | } | 165 | } | ||
208 | }); | 166 | }); | ||
Show All 18 Lines | 183 | protected void onDestroy() { | |||
227 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | 185 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | ||
228 | @Override | 186 | @Override | ||
229 | public void onServiceStart(BackgroundService service) { | 187 | public void onServiceStart(BackgroundService service) { | ||
230 | service.removeConnectionListener(connectionReceiver); | 188 | service.removeConnectionListener(connectionReceiver); | ||
231 | } | 189 | } | ||
232 | }); | 190 | }); | ||
233 | } | 191 | } | ||
234 | 192 | | |||
193 | private void updatePlayerStatus(MprisPlugin mpris) { | ||||
194 | MprisPlugin.MprisPlayer playerStatus = mpris.getPlayerStatus(targetPlayer); | ||||
195 | if (playerStatus == null) { | ||||
196 | //No player with that name found, just display "empty" data | ||||
197 | playerStatus = new MprisPlugin.MprisPlayer(); | ||||
198 | } | ||||
199 | String song = playerStatus.getCurrentSong(); | ||||
200 | | ||||
201 | TextView nowPlaying = (TextView) findViewById(R.id.now_playing_textview); | ||||
202 | if (!nowPlaying.getText().toString().equals(song)) { | ||||
203 | nowPlaying.setText(song); | ||||
204 | } | ||||
205 | | ||||
206 | //Hacks for Spotify because it reports incorrect info about what it supports | ||||
207 | boolean isSpotify = "spotify".equals(playerStatus.getPlayer().toLowerCase()); | ||||
thomasp: `MprisPlayer` could report correct info. | |||||
208 | | ||||
209 | if (playerStatus.getLength() > -1 && playerStatus.getPosition() > -1 && !isSpotify) { | ||||
210 | ((TextView) findViewById(R.id.time_textview)).setText(milisToProgress(playerStatus.getLength())); | ||||
211 | SeekBar positionSeek = (SeekBar)findViewById(R.id.positionSeek); | ||||
212 | positionSeek.setMax((int)(playerStatus.getLength())); | ||||
213 | positionSeek.setProgress((int)(playerStatus.getPosition())); | ||||
214 | findViewById(R.id.progress_slider).setVisibility(View.VISIBLE); | ||||
215 | } else { | ||||
216 | findViewById(R.id.progress_slider).setVisibility(View.GONE); | ||||
217 | } | ||||
218 | | ||||
219 | int volume = playerStatus.getVolume(); | ||||
220 | ((SeekBar) findViewById(R.id.volume_seek)).setProgress(volume); | ||||
221 | | ||||
222 | boolean isPlaying = playerStatus.isPlaying(); | ||||
223 | if (isPlaying) { | ||||
224 | ((ImageButton) findViewById(R.id.play_button)).setImageResource(android.R.drawable.ic_media_pause); | ||||
225 | findViewById(R.id.play_button).setVisibility(playerStatus.isPauseAllowed() ? View.VISIBLE : View.GONE); | ||||
226 | } else { | ||||
227 | ((ImageButton) findViewById(R.id.play_button)).setImageResource(android.R.drawable.ic_media_play); | ||||
228 | findViewById(R.id.play_button).setVisibility(playerStatus.isPlayAllowed() ? View.VISIBLE : View.GONE); | ||||
229 | } | ||||
230 | | ||||
231 | if (isSpotify) { | ||||
232 | findViewById(R.id.volume_layout).setVisibility(View.INVISIBLE); | ||||
233 | findViewById(R.id.rew_button).setVisibility(View.GONE); | ||||
234 | findViewById(R.id.ff_button).setVisibility(View.GONE); | ||||
235 | } else { | ||||
236 | findViewById(R.id.volume_layout).setVisibility(View.VISIBLE); | ||||
237 | findViewById(R.id.rew_button).setVisibility(playerStatus.isSeekAllowed() ? View.VISIBLE : View.GONE); | ||||
238 | findViewById(R.id.ff_button).setVisibility(playerStatus.isSeekAllowed() ? View.VISIBLE : View.GONE); | ||||
239 | } | ||||
240 | findViewById(R.id.next_button).setVisibility(playerStatus.isGoNextAllowed() ? View.VISIBLE : View.GONE); | ||||
241 | findViewById(R.id.prev_button).setVisibility(playerStatus.isGoPreviousAllowed() ? View.VISIBLE : View.GONE); | ||||
242 | } | ||||
243 | | ||||
235 | /** | 244 | /** | ||
236 | * Change current volume with provided step. | 245 | * Change current volume with provided step. | ||
237 | * | 246 | * | ||
238 | * @param mpris multimedia controller | 247 | * @param mpris multimedia controller | ||
239 | * @param step step size volume change | 248 | * @param step step size volume change | ||
240 | */ | 249 | */ | ||
241 | private void updateVolume(MprisPlugin mpris, int step) { | 250 | private void updateVolume(MprisPlugin mpris, int step) { | ||
242 | final int currentVolume = mpris.getVolume(); | 251 | MprisPlugin.MprisPlayer playerStatus = mpris.getPlayerStatus(targetPlayer); | ||
252 | if (playerStatus == null) { | ||||
253 | return; | ||||
254 | } | ||||
255 | final int currentVolume = playerStatus.getVolume(); | ||||
256 | | ||||
243 | if(currentVolume < 100 || currentVolume > 0) { | 257 | if(currentVolume < 100 || currentVolume > 0) { | ||
244 | int newVolume = currentVolume + step; | 258 | int newVolume = currentVolume + step; | ||
245 | if(newVolume > 100) { | 259 | if(newVolume > 100) { | ||
246 | newVolume = 100; | 260 | newVolume = 100; | ||
247 | } else if (newVolume <0 ) { | 261 | } else if (newVolume <0 ) { | ||
248 | newVolume = 0; | 262 | newVolume = 0; | ||
249 | } | 263 | } | ||
250 | mpris.setVolume(newVolume); | 264 | mpris.setVolume(targetPlayer, newVolume); | ||
251 | } | 265 | } | ||
252 | } | 266 | } | ||
253 | 267 | | |||
254 | @Override | 268 | @Override | ||
255 | public boolean onKeyDown(int keyCode, KeyEvent event) { | 269 | public boolean onKeyDown(int keyCode, KeyEvent event) { | ||
256 | switch (keyCode) { | 270 | switch (keyCode) { | ||
257 | case KeyEvent.KEYCODE_VOLUME_UP: | 271 | case KeyEvent.KEYCODE_VOLUME_UP: | ||
258 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | 272 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 332 | findViewById(R.id.play_button).setOnClickListener(new View.OnClickListener() { | |||
319 | @Override | 333 | @Override | ||
320 | public void onClick(View view) { | 334 | public void onClick(View view) { | ||
321 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | 335 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | ||
322 | @Override | 336 | @Override | ||
323 | public void onServiceStart(BackgroundService service) { | 337 | public void onServiceStart(BackgroundService service) { | ||
324 | Device device = service.getDevice(deviceId); | 338 | Device device = service.getDevice(deviceId); | ||
325 | MprisPlugin mpris = device.getPlugin(MprisPlugin.class); | 339 | MprisPlugin mpris = device.getPlugin(MprisPlugin.class); | ||
326 | if (mpris == null) return; | 340 | if (mpris == null) return; | ||
327 | mpris.sendAction("PlayPause"); | 341 | mpris.sendAction(targetPlayer, "PlayPause"); | ||
328 | } | 342 | } | ||
329 | }); | 343 | }); | ||
330 | } | 344 | } | ||
331 | }); | 345 | }); | ||
332 | 346 | | |||
333 | findViewById(R.id.prev_button).setOnClickListener(new View.OnClickListener() { | 347 | findViewById(R.id.prev_button).setOnClickListener(new View.OnClickListener() { | ||
334 | @Override | 348 | @Override | ||
335 | public void onClick(View view) { | 349 | public void onClick(View view) { | ||
336 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | 350 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | ||
337 | @Override | 351 | @Override | ||
338 | public void onServiceStart(BackgroundService service) { | 352 | public void onServiceStart(BackgroundService service) { | ||
339 | Device device = service.getDevice(deviceId); | 353 | Device device = service.getDevice(deviceId); | ||
340 | MprisPlugin mpris = device.getPlugin(MprisPlugin.class); | 354 | MprisPlugin mpris = device.getPlugin(MprisPlugin.class); | ||
341 | if (mpris == null) return; | 355 | if (mpris == null) return; | ||
342 | mpris.sendAction("Previous"); | 356 | mpris.sendAction(targetPlayer, "Previous"); | ||
343 | } | 357 | } | ||
344 | }); | 358 | }); | ||
345 | } | 359 | } | ||
346 | }); | 360 | }); | ||
347 | 361 | | |||
348 | findViewById(R.id.rew_button).setOnClickListener(new View.OnClickListener() { | 362 | findViewById(R.id.rew_button).setOnClickListener(new View.OnClickListener() { | ||
349 | @Override | 363 | @Override | ||
350 | public void onClick(View view) { | 364 | public void onClick(View view) { | ||
351 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | 365 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | ||
352 | @Override | 366 | @Override | ||
353 | public void onServiceStart(BackgroundService service) { | 367 | public void onServiceStart(BackgroundService service) { | ||
354 | Device device = service.getDevice(deviceId); | 368 | Device device = service.getDevice(deviceId); | ||
355 | MprisPlugin mpris = device.getPlugin(MprisPlugin.class); | 369 | MprisPlugin mpris = device.getPlugin(MprisPlugin.class); | ||
356 | if (mpris == null) return; | 370 | if (mpris == null) return; | ||
357 | mpris.Seek(interval_time * -1); | 371 | mpris.Seek(targetPlayer, interval_time * -1); | ||
358 | } | 372 | } | ||
359 | }); | 373 | }); | ||
360 | } | 374 | } | ||
361 | }); | 375 | }); | ||
362 | 376 | | |||
363 | findViewById(R.id.ff_button).setOnClickListener(new View.OnClickListener() { | 377 | findViewById(R.id.ff_button).setOnClickListener(new View.OnClickListener() { | ||
364 | @Override | 378 | @Override | ||
365 | public void onClick(View view) { | 379 | public void onClick(View view) { | ||
366 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | 380 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | ||
367 | @Override | 381 | @Override | ||
368 | public void onServiceStart(BackgroundService service) { | 382 | public void onServiceStart(BackgroundService service) { | ||
369 | Device device = service.getDevice(deviceId); | 383 | Device device = service.getDevice(deviceId); | ||
370 | MprisPlugin mpris = device.getPlugin(MprisPlugin.class); | 384 | MprisPlugin mpris = device.getPlugin(MprisPlugin.class); | ||
371 | if (mpris == null) return; | 385 | if (mpris == null) return; | ||
372 | mpris.Seek(interval_time); | 386 | mpris.Seek(targetPlayer, interval_time); | ||
373 | } | 387 | } | ||
374 | }); | 388 | }); | ||
375 | } | 389 | } | ||
376 | }); | 390 | }); | ||
377 | 391 | | |||
378 | findViewById(R.id.next_button).setOnClickListener(new View.OnClickListener() { | 392 | findViewById(R.id.next_button).setOnClickListener(new View.OnClickListener() { | ||
379 | @Override | 393 | @Override | ||
380 | public void onClick(View view) { | 394 | public void onClick(View view) { | ||
381 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | 395 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | ||
382 | @Override | 396 | @Override | ||
383 | public void onServiceStart(BackgroundService service) { | 397 | public void onServiceStart(BackgroundService service) { | ||
384 | Device device = service.getDevice(deviceId); | 398 | Device device = service.getDevice(deviceId); | ||
385 | MprisPlugin mpris = device.getPlugin(MprisPlugin.class); | 399 | MprisPlugin mpris = device.getPlugin(MprisPlugin.class); | ||
386 | if (mpris == null) return; | 400 | if (mpris == null) return; | ||
387 | mpris.sendAction("Next"); | 401 | mpris.sendAction(targetPlayer, "Next"); | ||
388 | } | 402 | } | ||
389 | }); | 403 | }); | ||
390 | } | 404 | } | ||
391 | }); | 405 | }); | ||
392 | 406 | | |||
393 | ((SeekBar)findViewById(R.id.volume_seek)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { | 407 | ((SeekBar)findViewById(R.id.volume_seek)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { | ||
394 | @Override | 408 | @Override | ||
395 | public void onProgressChanged(SeekBar seekBar, int i, boolean b) { | 409 | public void onProgressChanged(SeekBar seekBar, int i, boolean b) { | ||
396 | } | 410 | } | ||
397 | 411 | | |||
398 | @Override | 412 | @Override | ||
399 | public void onStartTrackingTouch(SeekBar seekBar) { | 413 | public void onStartTrackingTouch(SeekBar seekBar) { | ||
400 | } | 414 | } | ||
401 | 415 | | |||
402 | @Override | 416 | @Override | ||
403 | public void onStopTrackingTouch(final SeekBar seekBar) { | 417 | public void onStopTrackingTouch(final SeekBar seekBar) { | ||
404 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | 418 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | ||
405 | @Override | 419 | @Override | ||
406 | public void onServiceStart(BackgroundService service) { | 420 | public void onServiceStart(BackgroundService service) { | ||
407 | Device device = service.getDevice(deviceId); | 421 | Device device = service.getDevice(deviceId); | ||
408 | MprisPlugin mpris = device.getPlugin(MprisPlugin.class); | 422 | MprisPlugin mpris = device.getPlugin(MprisPlugin.class); | ||
409 | if (mpris == null) return; | 423 | if (mpris == null) return; | ||
410 | mpris.setVolume(seekBar.getProgress()); | 424 | mpris.setVolume(targetPlayer, seekBar.getProgress()); | ||
411 | } | 425 | } | ||
412 | }); | 426 | }); | ||
413 | } | 427 | } | ||
414 | 428 | | |||
415 | }); | 429 | }); | ||
416 | 430 | | |||
417 | positionSeekUpdateRunnable = new Runnable() { | 431 | positionSeekUpdateRunnable = new Runnable() { | ||
418 | @Override | 432 | @Override | ||
419 | public void run() { | 433 | public void run() { | ||
420 | final SeekBar positionSeek = (SeekBar)findViewById(R.id.positionSeek); | 434 | final SeekBar positionSeek = (SeekBar)findViewById(R.id.positionSeek); | ||
421 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | 435 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | ||
422 | @Override | 436 | @Override | ||
423 | public void onServiceStart(BackgroundService service) { | 437 | public void onServiceStart(BackgroundService service) { | ||
424 | Device device = service.getDevice(deviceId); | 438 | Device device = service.getDevice(deviceId); | ||
425 | if (device != null) { | 439 | if (device != null) { | ||
426 | MprisPlugin mpris = device.getPlugin(MprisPlugin.class); | 440 | MprisPlugin mpris = device.getPlugin(MprisPlugin.class); | ||
427 | if (mpris != null) { | 441 | if (mpris != null) { | ||
428 | positionSeek.setProgress((int) (mpris.getPosition())); | 442 | MprisPlugin.MprisPlayer playerStatus = mpris.getPlayerStatus(targetPlayer); | ||
443 | if (playerStatus != null) { | ||||
444 | positionSeek.setProgress((int) (playerStatus.getPosition())); | ||||
445 | } | ||||
429 | } | 446 | } | ||
430 | } | 447 | } | ||
431 | positionSeekUpdateHandler.removeCallbacks(positionSeekUpdateRunnable); | 448 | positionSeekUpdateHandler.removeCallbacks(positionSeekUpdateRunnable); | ||
432 | positionSeekUpdateHandler.postDelayed(positionSeekUpdateRunnable, 1000); | 449 | positionSeekUpdateHandler.postDelayed(positionSeekUpdateRunnable, 1000); | ||
433 | } | 450 | } | ||
434 | }); | 451 | }); | ||
435 | } | 452 | } | ||
436 | 453 | | |||
Show All 14 Lines | 457 | ((SeekBar)findViewById(R.id.positionSeek)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { | |||
451 | @Override | 468 | @Override | ||
452 | public void onStopTrackingTouch(final SeekBar seekBar) { | 469 | public void onStopTrackingTouch(final SeekBar seekBar) { | ||
453 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | 470 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | ||
454 | @Override | 471 | @Override | ||
455 | public void onServiceStart(BackgroundService service) { | 472 | public void onServiceStart(BackgroundService service) { | ||
456 | Device device = service.getDevice(deviceId); | 473 | Device device = service.getDevice(deviceId); | ||
457 | MprisPlugin mpris = device.getPlugin(MprisPlugin.class); | 474 | MprisPlugin mpris = device.getPlugin(MprisPlugin.class); | ||
458 | if (mpris != null) { | 475 | if (mpris != null) { | ||
459 | mpris.setPosition(seekBar.getProgress()); | 476 | mpris.setPosition(targetPlayer, seekBar.getProgress()); | ||
460 | } | 477 | } | ||
461 | positionSeekUpdateHandler.postDelayed(positionSeekUpdateRunnable, 200); | 478 | positionSeekUpdateHandler.postDelayed(positionSeekUpdateRunnable, 200); | ||
462 | } | 479 | } | ||
463 | }); | 480 | }); | ||
464 | } | 481 | } | ||
465 | 482 | | |||
466 | }); | 483 | }); | ||
467 | 484 | | |||
Show All 16 Lines |
targetPlayer is always null here. Please simplify beginning from line 143.