|
|
|
@ -43,9 +43,10 @@ import com.example.musicplayer.app.Api;
|
|
|
|
|
import com.example.musicplayer.app.Constant;
|
|
|
|
|
import com.example.musicplayer.base.activity.BaseMvpActivity;
|
|
|
|
|
import com.example.musicplayer.contract.IPlayContract;
|
|
|
|
|
import com.example.musicplayer.entiy.DownloadInfo;
|
|
|
|
|
import com.example.musicplayer.entiy.DownloadSong;
|
|
|
|
|
import com.example.musicplayer.entiy.LocalSong;
|
|
|
|
|
import com.example.musicplayer.entiy.Song;
|
|
|
|
|
import com.example.musicplayer.event.DownloadEvent;
|
|
|
|
|
import com.example.musicplayer.event.SongCollectionEvent;
|
|
|
|
|
import com.example.musicplayer.event.SongStatusEvent;
|
|
|
|
|
import com.example.musicplayer.presenter.PlayPresenter;
|
|
|
|
@ -64,18 +65,11 @@ import com.example.musicplayer.widget.LrcView;
|
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
|
|
|
import org.greenrobot.eventbus.ThreadMode;
|
|
|
|
|
import org.litepal.LitePal;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedOutputStream;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
|
|
import okhttp3.Connection;
|
|
|
|
|
import okhttp3.OkHttpClient;
|
|
|
|
|
import okhttp3.Request;
|
|
|
|
|
import okhttp3.Response;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 播放界面
|
|
|
|
@ -185,7 +179,7 @@ public class PlayActivity extends BaseMvpActivity<PlayPresenter> implements IPla
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
//绑定下载服务
|
|
|
|
|
private ServiceConnection mDownloadConnection =new ServiceConnection() {
|
|
|
|
|
private ServiceConnection mDownloadConnection = new ServiceConnection() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
|
|
|
|
mDownloadBinder = (DownloadService.DownloadBinder) iBinder;
|
|
|
|
@ -226,9 +220,9 @@ public class PlayActivity extends BaseMvpActivity<PlayPresenter> implements IPla
|
|
|
|
|
|
|
|
|
|
//绑定服务,播放和下载的服务
|
|
|
|
|
Intent playIntent = new Intent(PlayActivity.this, PlayerService.class);
|
|
|
|
|
Intent downIntent = new Intent(PlayActivity.this,DownloadService.class);
|
|
|
|
|
Intent downIntent = new Intent(PlayActivity.this, DownloadService.class);
|
|
|
|
|
bindService(playIntent, mPlayConnection, Context.BIND_AUTO_CREATE);
|
|
|
|
|
bindService(downIntent,mDownloadConnection,Context.BIND_AUTO_CREATE);
|
|
|
|
|
bindService(downIntent, mDownloadConnection, Context.BIND_AUTO_CREATE);
|
|
|
|
|
|
|
|
|
|
//界面填充
|
|
|
|
|
mSong = FileUtil.getSong();
|
|
|
|
@ -239,19 +233,31 @@ public class PlayActivity extends BaseMvpActivity<PlayPresenter> implements IPla
|
|
|
|
|
mSeekBar.setMax((int) mSong.getDuration());
|
|
|
|
|
mSeekBar.setProgress((int) mSong.getCurrentTime());
|
|
|
|
|
mDownLoadIv.setVisibility(mSong.isOnline() ? View.VISIBLE : View.GONE); //下载按钮是否隐藏
|
|
|
|
|
mDownLoadIv.setImageDrawable(mSong.isDownload() ? getDrawable(R.drawable.downloaded) : getDrawable(R.drawable.download_song));
|
|
|
|
|
|
|
|
|
|
mPlayMode = mPresenter.getPlayMode();//得到播放模式
|
|
|
|
|
if(mPlayMode == Constant.PLAY_ORDER){
|
|
|
|
|
if (mPlayMode == Constant.PLAY_ORDER) {
|
|
|
|
|
mPlayModeBtn.setBackground(getDrawable(R.drawable.play_mode_order));
|
|
|
|
|
}else if(mPlayMode == Constant.PLAY_RANDOM){
|
|
|
|
|
} else if (mPlayMode == Constant.PLAY_RANDOM) {
|
|
|
|
|
mPlayModeBtn.setBackground(getDrawable(R.drawable.play_mode_random));
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
mPlayModeBtn.setBackground(getDrawable(R.drawable.play_mode_single));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
|
|
public void onDownloadSuccessEvent(DownloadEvent event){
|
|
|
|
|
if(event.getDownloadStatus() == Constant.TYPE_DOWNLOAD_SUCCESS){
|
|
|
|
|
mDownLoadIv.setImageDrawable(
|
|
|
|
|
LitePal.where("songId=?", mSong.getSongId()).find(DownloadSong.class).size() != 0
|
|
|
|
|
? getDrawable(R.drawable.downloaded)
|
|
|
|
|
: getDrawable(R.drawable.download_song));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected PlayPresenter getPresenter() {
|
|
|
|
|
//与Presenter建立关系
|
|
|
|
@ -341,7 +347,7 @@ public class PlayActivity extends BaseMvpActivity<PlayPresenter> implements IPla
|
|
|
|
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
|
|
|
|
if (mPlayStatusBinder.isPlaying()) {
|
|
|
|
|
mMediaPlayer = mPlayStatusBinder.getMediaPlayer();
|
|
|
|
|
mMediaPlayer.seekTo(seekBar.getProgress()*1000);
|
|
|
|
|
mMediaPlayer.seekTo(seekBar.getProgress() * 1000);
|
|
|
|
|
startUpdateSeekBarProgress();
|
|
|
|
|
} else {
|
|
|
|
|
time = seekBar.getProgress();
|
|
|
|
@ -367,8 +373,8 @@ public class PlayActivity extends BaseMvpActivity<PlayPresenter> implements IPla
|
|
|
|
|
mPlayStatusBinder.resume();
|
|
|
|
|
flag = false;
|
|
|
|
|
if (isSeek) {
|
|
|
|
|
Log.d(TAG, "onClick: "+time);
|
|
|
|
|
mMediaPlayer.seekTo(time*1000);
|
|
|
|
|
Log.d(TAG, "onClick: " + time);
|
|
|
|
|
mMediaPlayer.seekTo(time * 1000);
|
|
|
|
|
isSeek = false;
|
|
|
|
|
}
|
|
|
|
|
mDisc.play();
|
|
|
|
@ -380,7 +386,7 @@ public class PlayActivity extends BaseMvpActivity<PlayPresenter> implements IPla
|
|
|
|
|
} else {
|
|
|
|
|
mPlayStatusBinder.play(mListType);
|
|
|
|
|
}
|
|
|
|
|
mMediaPlayer.seekTo((int) mSong.getCurrentTime()*1000);
|
|
|
|
|
mMediaPlayer.seekTo((int) mSong.getCurrentTime() * 1000);
|
|
|
|
|
mDisc.play();
|
|
|
|
|
mPlayBtn.setSelected(true);
|
|
|
|
|
startUpdateSeekBarProgress();
|
|
|
|
@ -419,18 +425,18 @@ public class PlayActivity extends BaseMvpActivity<PlayPresenter> implements IPla
|
|
|
|
|
String lrc = FileUtil.getLrcFromNative(mSong.getSongName());
|
|
|
|
|
if (null == lrc) {
|
|
|
|
|
String qqId = mSong.getQqId();
|
|
|
|
|
if(Constant.SONG_ID_UNFIND.equals(qqId)){//匹配不到歌词
|
|
|
|
|
if (Constant.SONG_ID_UNFIND.equals(qqId)) {//匹配不到歌词
|
|
|
|
|
getLrcError(null);
|
|
|
|
|
}else if(null == qqId){//歌曲的id还未匹配
|
|
|
|
|
mPresenter.getSongId(mSong.getSongName(),mSong.getDuration());
|
|
|
|
|
}else {//歌词还未匹配
|
|
|
|
|
mPresenter.getLrc(qqId,Constant.SONG_LOCAL);
|
|
|
|
|
} else if (null == qqId) {//歌曲的id还未匹配
|
|
|
|
|
mPresenter.getSongId(mSong.getSongName(), mSong.getDuration());
|
|
|
|
|
} else {//歌词还未匹配
|
|
|
|
|
mPresenter.getLrc(qqId, Constant.SONG_LOCAL);
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
showLrc(lrc);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
mPresenter.getLrc(mSong.getSongId(),Constant.SONG_ONLINE);
|
|
|
|
|
mPresenter.getLrc(mSong.getSongId(), Constant.SONG_ONLINE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
@ -441,7 +447,11 @@ public class PlayActivity extends BaseMvpActivity<PlayPresenter> implements IPla
|
|
|
|
|
});
|
|
|
|
|
//歌曲下载
|
|
|
|
|
mDownLoadIv.setOnClickListener(v -> {
|
|
|
|
|
mDownloadBinder.startDownload(mSong);
|
|
|
|
|
if (mSong.isDownload()) {
|
|
|
|
|
showToast(getString(R.string.downloded));
|
|
|
|
|
} else {
|
|
|
|
|
mDownloadBinder.startDownload(mSong);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -647,20 +657,20 @@ public class PlayActivity extends BaseMvpActivity<PlayPresenter> implements IPla
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void getSongIdSuccess(String songId) {
|
|
|
|
|
Log.d(TAG, "getSongIdSuccess: "+songId);
|
|
|
|
|
Log.d(TAG, "getSongIdSuccess: " + songId);
|
|
|
|
|
setLocalSongId(songId);//保存音乐信息
|
|
|
|
|
mPresenter.getLrc(songId,Constant.SONG_LOCAL);//获取歌词
|
|
|
|
|
mPresenter.getLrc(songId, Constant.SONG_LOCAL);//获取歌词
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void saveLrc(String lrc) {
|
|
|
|
|
FileUtil.saveLrcToNative(lrc,mSong.getSongName());
|
|
|
|
|
FileUtil.saveLrcToNative(lrc, mSong.getSongName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//改变播放模式
|
|
|
|
|
private void changePlayMode(){
|
|
|
|
|
View playModeView = LayoutInflater.from(this).inflate(R.layout.play_mode,null);
|
|
|
|
|
private void changePlayMode() {
|
|
|
|
|
View playModeView = LayoutInflater.from(this).inflate(R.layout.play_mode, null);
|
|
|
|
|
ConstraintLayout orderLayout = playModeView.findViewById(R.id.orderLayout);
|
|
|
|
|
ConstraintLayout randomLayout = playModeView.findViewById(R.id.randomLayout);
|
|
|
|
|
ConstraintLayout singleLayout = playModeView.findViewById(R.id.singleLayout);
|
|
|
|
@ -669,7 +679,7 @@ public class PlayActivity extends BaseMvpActivity<PlayPresenter> implements IPla
|
|
|
|
|
TextView singleTv = playModeView.findViewById(R.id.singleTv);
|
|
|
|
|
|
|
|
|
|
//显示弹窗
|
|
|
|
|
PopupWindow popupWindow = new PopupWindow(playModeView, ScreenUtil.dip2px(this,130),ScreenUtil.dip2px(this,150));
|
|
|
|
|
PopupWindow popupWindow = new PopupWindow(playModeView, ScreenUtil.dip2px(this, 130), ScreenUtil.dip2px(this, 150));
|
|
|
|
|
//设置背景色
|
|
|
|
|
popupWindow.setBackgroundDrawable(getDrawable(R.color.transparent));
|
|
|
|
|
//设置焦点
|
|
|
|
@ -678,20 +688,20 @@ public class PlayActivity extends BaseMvpActivity<PlayPresenter> implements IPla
|
|
|
|
|
popupWindow.setOutsideTouchable(true);
|
|
|
|
|
popupWindow.update();
|
|
|
|
|
//设置弹出的位置
|
|
|
|
|
popupWindow.showAsDropDown(mPlayModeBtn,0,-50);
|
|
|
|
|
popupWindow.showAsDropDown(mPlayModeBtn, 0, -50);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//显示播放模式
|
|
|
|
|
int mode = mPresenter.getPlayMode();
|
|
|
|
|
if(mode == Constant.PLAY_ORDER){
|
|
|
|
|
if (mode == Constant.PLAY_ORDER) {
|
|
|
|
|
orderTv.setSelected(true);
|
|
|
|
|
randomTv.setSelected(false);
|
|
|
|
|
singleTv.setSelected(false);
|
|
|
|
|
}else if(mode == Constant.PLAY_RANDOM){
|
|
|
|
|
} else if (mode == Constant.PLAY_RANDOM) {
|
|
|
|
|
randomTv.setSelected(true);
|
|
|
|
|
orderTv.setSelected(false);
|
|
|
|
|
singleTv.setSelected(false);
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
singleTv.setSelected(true);
|
|
|
|
|
randomTv.setSelected(false);
|
|
|
|
|
orderTv.setSelected(false);
|
|
|
|
|