Refactor the switch statement.

This commit is contained in:
Swapnil Tripathi 2021-08-14 20:31:30 +05:30 committed by Tobias Fella
parent 09005b232d
commit f43eecb74a

View File

@ -41,6 +41,7 @@ public class KastsActivity extends QtActivity
public long position;
public long duration;
public float playbackSpeed;
public int state = 2;
// add more variables here
}
@ -57,6 +58,16 @@ public class KastsActivity extends QtActivity
MediaMetadataCompat.Builder metadata = new MediaMetadataCompat.Builder();
switch(mediaData.state)
{
case 0:
mPBuilder.setState(PlaybackStateCompat.STATE_PLAYING, mediaData.position, mediaData.playbackSpeed);
case 1:
mPBuilder.setState(PlaybackStateCompat.STATE_PAUSED, mediaData.position, mediaData.playbackSpeed);
case 2:
mPBuilder.setState(PlaybackStateCompat.STATE_STOPPED, mediaData.position, mediaData.playbackSpeed);
}
metadata.putString(MediaMetadataCompat.METADATA_KEY_TITLE, "The title");
metadata.putString(MediaMetadataCompat.METADATA_KEY_AUTHOR, "Author");
metadata.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, "Author");
@ -194,15 +205,9 @@ public class KastsActivity extends QtActivity
public static void setSessionState(int state)
{
//TODO: set state in mediadata
switch(state)
{
case 0:
mPBuilder.setState(PlaybackStateCompat.STATE_PLAYING, mediaData.position, mediaData.playbackSpeed);
case 1:
mPBuilder.setState(PlaybackStateCompat.STATE_PAUSED, mediaData.position, mediaData.playbackSpeed);
case 2:
mPBuilder.setState(PlaybackStateCompat.STATE_STOPPED, mediaData.position, mediaData.playbackSpeed);
}
mediaData.state = state;
activity.updateNotification();
}