diff --git a/res/layout/mpris_control.xml b/res/layout/mpris_control.xml index 5a0b8e83..e5c597f4 100644 --- a/res/layout/mpris_control.xml +++ b/res/layout/mpris_control.xml @@ -91,7 +91,8 @@ + android:layout_height="wrap_content" + android:id="@+id/progress_slider"> 60) { + int hours = minutes / 60; + minutes = minutes % 60; + text.append(hours).append(':'); + if (minutes < 10) text.append('0'); + } + text.append(minutes).append(':'); + int seconds = (length % 60); + if(seconds < 10) text.append('0'); // needed to show length properly (eg 4:05 instead of 4:5) + text.append(seconds); + return text.toString(); + } protected void connectToPlugin() { final String deviceId = getIntent().getStringExtra("deviceId"); @@ -79,25 +95,21 @@ public class MprisActivity extends ActionBarActivity { String s = mpris.getCurrentSong(); ((TextView) findViewById(R.id.now_playing_textview)).setText(s); + if (mpris.getLength() > -1 && mpris.getPosition() > -1 && !"Spotify".equals(mpris.getPlayer())) { + ((TextView) findViewById(R.id.time_textview)).setText(milisToProgress(mpris.getLength())); - String text = mpris.getLength() / 60000000 + ":"; - int seconds = (mpris.getLength() % 60000000) / 1000000; - // needed to show length properly (eg 4:05 instead of 4:5) - if(seconds < 10) text = text + "0"; - text = text + seconds; + SeekBar positionSeek = (SeekBar)findViewById(R.id.positionSeek); + positionSeek.setMax((int)(mpris.getLength())); + positionSeek.setProgress((int)(mpris.getPosition())); - SeekBar positionSeek = (SeekBar)findViewById(R.id.positionSeek); - positionSeek.setMax(mpris.getLength()); - positionSeek.setProgress(mpris.getPosition()); + findViewById(R.id.progress_slider).setVisibility(View.VISIBLE); + } else { + findViewById(R.id.progress_slider).setVisibility(View.GONE); + } int volume = mpris.getVolume(); - ((TextView) findViewById(R.id.time_textview)).setText(text); - - ((SeekBar) findViewById(R.id.volume_seek)).setProgress(volume); - - boolean isPlaying = mpris.isPlaying(); if (isPlaying) { ((ImageButton) findViewById(R.id.play_button)).setImageResource(android.R.drawable.ic_media_pause); @@ -145,6 +157,7 @@ public class MprisActivity extends ActionBarActivity { findViewById(R.id.rew_button).setVisibility(View.GONE); findViewById(R.id.ff_button).setVisibility(View.GONE); findViewById(R.id.positionSeek).setVisibility(View.INVISIBLE); + findViewById(R.id.progress_slider).setVisibility(View.GONE); } else { findViewById(R.id.volume_layout).setVisibility(View.VISIBLE); findViewById(R.id.rew_button).setVisibility(View.VISIBLE); @@ -397,7 +410,7 @@ public class MprisActivity extends ActionBarActivity { Device device = service.getDevice(deviceId); MprisPlugin mpris = (MprisPlugin) device.getPlugin("plugin_mpris"); if (mpris == null) return; - positionSeek.setProgress(mpris.getPosition()); + positionSeek.setProgress((int)(mpris.getPosition())); if(!mpris.isPlaying()) return; positionSeekUpdateHandler.postDelayed(thisRunnable, 1000); positionSeekUpdateScheduled = true; @@ -412,11 +425,7 @@ public class MprisActivity extends ActionBarActivity { ((SeekBar)findViewById(R.id.positionSeek)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean byUser) { - String text = progress / 60000000 + ":"; - int seconds = (progress % 60000000) / 1000000; - if(seconds < 10) text = text + "0"; - text = text + seconds; - ((TextView)findViewById(R.id.progress_textview)).setText(text); + ((TextView)findViewById(R.id.progress_textview)).setText(milisToProgress(progress)); } @Override diff --git a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java index 666f4c5c..866da9ae 100644 --- a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java @@ -42,8 +42,8 @@ public class MprisPlugin extends Plugin { private String currentSong = ""; private int volume = 50; - private int length = 0; - private int lastPosition; + private long length = -1; + private long lastPosition; private long lastPositionTime; private Handler playerStatusUpdated = null; @@ -134,9 +134,9 @@ public class MprisPlugin extends Plugin { if (np.getString("player").equals(player)) { currentSong = np.getString("nowPlaying", currentSong); volume = np.getInt("volume", volume); - length = np.getInt("length", length); + length = np.getLong("length", length); if(np.has("pos")){ - lastPosition = np.getInt("pos", lastPosition); + lastPosition = np.getLong("pos", lastPosition); lastPositionTime = System.currentTimeMillis(); } playing = np.getBoolean("isPlaying", playing); @@ -227,18 +227,18 @@ public class MprisPlugin extends Plugin { return volume; } - public int getLength(){ return length; } + public long getLength(){ return length; } public boolean isPlaying() { return playing; } - public int getPosition(){ - - if(playing) - return lastPosition + (int)(System.currentTimeMillis() - lastPositionTime)*1000; - else + public long getPosition(){ + if(playing) { + return lastPosition + (System.currentTimeMillis() - lastPositionTime); + } else { return lastPosition; + } } private void requestPlayerList() { @@ -247,7 +247,6 @@ public class MprisPlugin extends Plugin { device.sendPackage(np); } - private void requestPlayerStatus() { NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MPRIS); np.set("player",player);