diff --git a/app/src/main/java/com/yutou/nas_music_player/Datas/MusicData.java b/app/src/main/java/com/yutou/nas_music_player/Datas/MusicData.java index 9dbd025..c44f372 100644 --- a/app/src/main/java/com/yutou/nas_music_player/Datas/MusicData.java +++ b/app/src/main/java/com/yutou/nas_music_player/Datas/MusicData.java @@ -136,6 +136,11 @@ public class MusicData { if (StringUtil.isEmpty(track)) { return "0"; } + try{ + Integer.parseInt(track); + }catch (Exception e){ + return track.substring(0,1); + } return track; } diff --git a/app/src/main/java/com/yutou/nas_music_player/containers/MediaBrowserHelper.java b/app/src/main/java/com/yutou/nas_music_player/containers/MediaBrowserHelper.java index 50406c5..758c5c5 100644 --- a/app/src/main/java/com/yutou/nas_music_player/containers/MediaBrowserHelper.java +++ b/app/src/main/java/com/yutou/nas_music_player/containers/MediaBrowserHelper.java @@ -134,7 +134,7 @@ public class MediaBrowserHelper { } } - public class MediaBrowserSubscriptionCallback extends MediaBrowserCompat.SubscriptionCallback { + public static class MediaBrowserSubscriptionCallback extends MediaBrowserCompat.SubscriptionCallback { } } diff --git a/app/src/main/java/com/yutou/nas_music_player/services/MusicService.java b/app/src/main/java/com/yutou/nas_music_player/services/MusicService.java index a4de868..9767cb1 100644 --- a/app/src/main/java/com/yutou/nas_music_player/services/MusicService.java +++ b/app/src/main/java/com/yutou/nas_music_player/services/MusicService.java @@ -125,7 +125,9 @@ public class MusicService extends MediaBrowserServiceCompat { IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY);; public void updateNotification() { + MediaMetadataCompat metadataCompat = MusicContainer.getInstance().getNowPlayMetadataCompat(); + System.out.println("更新通知栏:"+metadataCompat.getString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID)); mediaSession.setMetadata(metadataCompat); mediaSession.setActive(true); Notification notification = diff --git a/app/src/main/java/com/yutou/nas_music_player/views/MainActivity.java b/app/src/main/java/com/yutou/nas_music_player/views/MainActivity.java index 1b34ac0..4ee17f6 100644 --- a/app/src/main/java/com/yutou/nas_music_player/views/MainActivity.java +++ b/app/src/main/java/com/yutou/nas_music_player/views/MainActivity.java @@ -51,7 +51,6 @@ public class MainActivity extends AppCompatActivity { private TextView positionTime, durationTime, bitRate; private SeekBar seekBar; private Handler handler; - private KProgressHUD hud; @Override protected void onCreate(Bundle savedInstanceState) { @@ -64,11 +63,7 @@ public class MainActivity extends AppCompatActivity { play.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (hud != null) { - hud.dismiss(); - hud = null; - } - hud = AppTools.showLoading(MainActivity.this); + handler.post(new Runnable() { @Override public void run() { @@ -78,10 +73,6 @@ public class MainActivity extends AppCompatActivity { } else { browserHelper.getTransportControls().play(); } - if (hud != null && hud.isShowing()) { - hud.dismiss(); - hud = null; - } } }); @@ -90,19 +81,12 @@ public class MainActivity extends AppCompatActivity { next.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (hud != null) { - hud.dismiss(); - hud = null; - } - hud = AppTools.showLoading(MainActivity.this); + handler.post(new Runnable() { @Override public void run() { browserHelper.getTransportControls().skipToNext(); - if (hud != null && hud.isShowing()) { - hud.dismiss(); - hud = null; - } + } }); @@ -111,19 +95,10 @@ public class MainActivity extends AppCompatActivity { previous.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (hud != null) { - hud.dismiss(); - hud = null; - } - hud = AppTools.showLoading(MainActivity.this); handler.post(new Runnable() { @Override public void run() { browserHelper.getTransportControls().skipToPrevious(); - if (hud != null && hud.isShowing()) { - hud.dismiss(); - hud = null; - } } }); } @@ -141,19 +116,11 @@ public class MainActivity extends AppCompatActivity { @Override public void onStopTrackingTouch(SeekBar seekBar) { - if (hud != null) { - hud.dismiss(); - hud = null; - } - hud = AppTools.showLoading(MainActivity.this); handler.post(new Runnable() { @Override public void run() { - if (browserHelper.getTransportControls() != null) + if (browserHelper.getTransportControls() != null) { browserHelper.getTransportControls().seekTo(MainActivity.this.seekBar.getProgress()); - if (hud != null && hud.isShowing()) { - hud.dismiss(); - hud = null; } } }); @@ -200,7 +167,7 @@ public class MainActivity extends AppCompatActivity { Intent intent = new Intent( MainActivity.this, PlayLibsActivity.class); - intent.putExtra("bar_pos",seekBar.getProgress()); + intent.putExtra("bar_pos", seekBar.getProgress()); if (bundle != null) { startActivity(intent, bundle); } else { @@ -251,13 +218,13 @@ public class MainActivity extends AppCompatActivity { + String.format(Locale.CHINA, "%02d", seconds)); int model = ConfigTools.getPreferences().getInt("playModel", MusicContainer.PLAY_MODEL_RANDOM); setPlayModelButton(model); - if (data.getImg(-1,-1) != null) { + if (data.getImg(-1, -1) != null) { setImage(data); } else { new Timer().schedule(new TimerTask() { @Override public void run() { - if (data.getImg(-1,-1) != null) { + if (data.getImg(-1, -1) != null) { AppData.handler.post(new Runnable() { @Override public void run() { @@ -294,10 +261,10 @@ public class MainActivity extends AppCompatActivity { private void setImage(MusicData data) { setBarColor(data.getImageColor()); - Glide.with(this).load(data.getImg(-1,-1)) + Glide.with(this).load(data.getImg(-1, -1)) .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(25, 3))) .into(album_image); - Glide.with(this).load(data.getImg(200,200)) + Glide.with(this).load(data.getImg(200, 200)) .apply(RequestOptions.bitmapTransform(new BlurTransformation(25, 3))) .into(background_image); } @@ -326,9 +293,9 @@ public class MainActivity extends AppCompatActivity { @Override protected void onDestroy() { super.onDestroy(); - if(browserHelper!=null){ + if (browserHelper != null) { browserHelper.onStop(); - browserHelper=null; + browserHelper = null; } finish(); }