Commit 6566127c by konghaorui

新增通知栏音乐播放打开意图

parent 2175c230
...@@ -30,9 +30,13 @@ ...@@ -30,9 +30,13 @@
android:theme="@style/platform_NoTitleTheme"> android:theme="@style/platform_NoTitleTheme">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
<intent-filter>
<action android:name="com.ydl.media.ACTION_MUSIC_CLICK" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity> </activity>
<meta-data <meta-data
......
...@@ -17,7 +17,7 @@ import com.ydl.media.music.AudioPlayer; ...@@ -17,7 +17,7 @@ import com.ydl.media.music.AudioPlayer;
import com.ydl.media.music.OnPlayerEventListener; import com.ydl.media.music.OnPlayerEventListener;
import com.ydl.media.music.enums.PlayModeEnum; import com.ydl.media.music.enums.PlayModeEnum;
import com.ydl.media.music.model.Music; import com.ydl.media.music.model.Music;
import com.ydl.media.music.utils.ImageUtils; import com.ydl.media.music.utils.CoverImageUtils;
import com.yidianling.common.tools.ToastUtil; import com.yidianling.common.tools.ToastUtil;
import java.util.Locale; import java.util.Locale;
...@@ -200,9 +200,11 @@ public class PlayFragment extends Fragment implements View.OnClickListener, ...@@ -200,9 +200,11 @@ public class PlayFragment extends Fragment implements View.OnClickListener,
tvArtist.setText(music.getArtist()); tvArtist.setText(music.getArtist());
sbProgress.setProgress((int) AudioPlayer.Companion.get().getAudioPosition()); sbProgress.setProgress((int) AudioPlayer.Companion.get().getAudioPosition());
sbProgress.setSecondaryProgress(0); sbProgress.setSecondaryProgress(0);
sbProgress.setMax((int) AudioPlayer.Companion.get().getDuration());
mLastProgress = 0; mLastProgress = 0;
tvCurrentTime.setText(R.string.play_time_start); tvCurrentTime.setText(R.string.play_time_start);
tvTotalTime.setText(formatTime(AudioPlayer.Companion.get().getDuration()));
setCoverAndBg(music); setCoverAndBg(music);
if (AudioPlayer.Companion.get().isPlaying() || AudioPlayer.Companion.get().isPreparing()) { if (AudioPlayer.Companion.get().isPlaying() || AudioPlayer.Companion.get().isPreparing()) {
...@@ -250,8 +252,8 @@ public class PlayFragment extends Fragment implements View.OnClickListener, ...@@ -250,8 +252,8 @@ public class PlayFragment extends Fragment implements View.OnClickListener,
} }
void setCoverAndBg(Music music) { void setCoverAndBg(Music music) {
ImageUtils.INSTANCE.loadRound(Objects.requireNonNull(music.getCoverPath()), bitmap -> ivCover.setImageBitmap(bitmap)); CoverImageUtils.INSTANCE.loadRound(Objects.requireNonNull(music.getCoverPath()), bitmap -> ivCover.setImageBitmap(bitmap));
ImageUtils.INSTANCE.loadBlur(music.getCoverPath(), bitmap -> ivPlayingBg.setImageBitmap(bitmap)); CoverImageUtils.INSTANCE.loadBlur(music.getCoverPath(), bitmap -> ivPlayingBg.setImageBitmap(bitmap));
} }
String formatTime(long time) { String formatTime(long time) {
......
...@@ -360,11 +360,7 @@ class AudioPlayer private constructor() { ...@@ -360,11 +360,7 @@ class AudioPlayer private constructor() {
else -> playPosition + 1 else -> playPosition + 1
} }
play(playPosition); play(playPosition);
} }
/** /**
...@@ -421,6 +417,10 @@ class AudioPlayer private constructor() { ...@@ -421,6 +417,10 @@ class AudioPlayer private constructor() {
return musicList return musicList
} }
fun getDuration(): Long{
return if (isPlaying) mediaPlayer!!.duration else 0
}
companion object { companion object {
private val STATE_IDLE = 0 private val STATE_IDLE = 0
......
...@@ -8,7 +8,7 @@ import android.support.v4.media.session.PlaybackStateCompat ...@@ -8,7 +8,7 @@ import android.support.v4.media.session.PlaybackStateCompat
import com.ydl.media.music.AudioPlayer import com.ydl.media.music.AudioPlayer
import com.ydl.media.music.PlayService import com.ydl.media.music.PlayService
import com.ydl.media.music.model.Music import com.ydl.media.music.model.Music
import com.ydl.media.music.utils.ImageUtils import com.ydl.media.music.utils.CoverImageUtils
/** /**
...@@ -79,7 +79,7 @@ class MediaSessionManager private constructor() { ...@@ -79,7 +79,7 @@ class MediaSessionManager private constructor() {
return return
} }
ImageUtils.loadThumb(music.coverPath!!,object :ImageUtils.OnCoverLoadListenre{ CoverImageUtils.loadThumb(music.coverPath!!,object :CoverImageUtils.OnCoverLoadListenre{
override fun onComplete(bitmap: Bitmap) { override fun onComplete(bitmap: Bitmap) {
val metaData = MediaMetadataCompat.Builder() val metaData = MediaMetadataCompat.Builder()
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, music.title) .putString(MediaMetadataCompat.METADATA_KEY_TITLE, music.title)
......
...@@ -68,11 +68,10 @@ class NotifyManager private constructor() { ...@@ -68,11 +68,10 @@ class NotifyManager private constructor() {
music: Music, music: Music,
isPlaying: Boolean isPlaying: Boolean
): Notification { ): Notification {
// TODO: 2019-10-26 by:HaoRui
// Intent intent = new Intent(context, MusicActivity.class);
val intent = Intent() val intent = Intent()
intent.action= "com.ydl.media.ACTION_MUSIC_CLICK"
intent.putExtra(Extras.EXTRA_NOTIFICATION, true) intent.putExtra(Extras.EXTRA_NOTIFICATION, true)
intent.action = Intent.ACTION_VIEW
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
......
...@@ -29,6 +29,7 @@ class StatusBarReceiver : BroadcastReceiver() { ...@@ -29,6 +29,7 @@ class StatusBarReceiver : BroadcastReceiver() {
companion object { companion object {
val ACTION_STATUS_BAR = "com.ydl.media.STATUS_BAR_ACTIONS" val ACTION_STATUS_BAR = "com.ydl.media.STATUS_BAR_ACTIONS"
val ACTION_MUSIC_CLICK = "com.ydl.media.ACTION_MUSIC_CLICK"
val EXTRA = "extra" val EXTRA = "extra"
val EXTRA_NEXT = "next" val EXTRA_NEXT = "next"
val EXTRA_PLAY_PAUSE = "play_pause" val EXTRA_PLAY_PAUSE = "play_pause"
......
...@@ -13,7 +13,7 @@ import com.ydl.ydlcommon.base.BaseApp ...@@ -13,7 +13,7 @@ import com.ydl.ydlcommon.base.BaseApp
* Created by haorui on 2019-10-27 . * Created by haorui on 2019-10-27 .
* Des: * Des:
*/ */
object ImageUtils { object CoverImageUtils {
private val BLUR_RADIUS = 50 private val BLUR_RADIUS = 50
fun blur(source: Bitmap?): Bitmap? { fun blur(source: Bitmap?): Bitmap? {
...@@ -373,7 +373,7 @@ object ImageUtils { ...@@ -373,7 +373,7 @@ object ImageUtils {
RequestOptions().format(DecodeFormat.PREFER_RGB_565).disallowHardwareConfig() RequestOptions().format(DecodeFormat.PREFER_RGB_565).disallowHardwareConfig()
Glide.with(BaseApp.getApp()).asBitmap().apply(disallowHardwareConfig).load(url).into(object : SimpleTarget<Bitmap>() { Glide.with(BaseApp.getApp()).asBitmap().apply(disallowHardwareConfig).load(url).into(object : SimpleTarget<Bitmap>() {
override fun onResourceReady(resource: Bitmap?, transition: Transition<in Bitmap>?) { override fun onResourceReady(resource: Bitmap?, transition: Transition<in Bitmap>?) {
onCoverLoadListener.onComplete(ImageUtils.blur(resource)!!) onCoverLoadListener.onComplete(CoverImageUtils.blur(resource)!!)
} }
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment