2024年Android应用开发-MP3音乐播放器代码实现(三),华为的面试难吗

最后笔者收集整理了一份Flutter高级入门进阶资料PDF

以下是资料目录和内容部分截图



里面包括详细的知识点讲解分析,带你一个星期入门Flutter。还有130个进阶学习项目实战视频教程,让你秒变大前端。

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

case isAllRepeat: // 全部循环

shuffleBtn.setClickable(false);

repeatBtn.setBackgroundResource(R.drawable.repeat_all_selector);

break;

case isNoneRepeat: // 无重复

shuffleBtn.setClickable(true);

repeatBtn.setBackgroundResource(R.drawable.repeat_none_selector);

break;

}

if(isShuffle) {

isNoneShuffle = false;

shuffleBtn.setBackgroundResource(R.drawable.shuffle_selector);

repeatBtn.setClickable(false);

} else {

isNoneShuffle = true;

shuffleBtn.setBackgroundResource(R.drawable.shuffle_none_selector);

repeatBtn.setClickable(true);

}

if(flag == AppConstant.PlayerMsg.PLAYING_MSG) { //如果播放信息是正在播放

Toast.makeText(PlayerActivity.this, “正在播放–” + title, 1).show();

}

else if(flag == AppConstant.PlayerMsg.PLAY_MSG) { //如果是点击列表播放歌曲的话

play();

}

playBtn.setBackgroundResource(R.drawable.play_selector);

isPlaying = true;

isPause = false;

}

/**

  • 反注册广播

*/

@Override

protected void onStop() {

super.onStop();

unregisterReceiver(playerReceiver);

}

@Override

protected void onDestroy() {

super.onDestroy();

}

/**

  • 控件点击事件

  • @author wwj

*/

private class ViewOnclickListener implements OnClickListener {

Intent intent = new Intent();

@Override

public void onClick(View v) {

switch(v.getId()) {

case R.id.play_music:

if (isPlaying) {

playBtn.setBackgroundResource(R.drawable.pause_selector);

intent.setAction(“com.wwj.media.MUSIC_SERVICE”);

intent.putExtra(“MSG”, AppConstant.PlayerMsg.PAUSE_MSG);

startService(intent);

isPlaying = false;

isPause = true;

} else if (isPause) {

playBtn.setBackgroundResource(R.drawable.play_selector);

intent.setAction(“com.wwj.media.MUSIC_SERVICE”);

intent.putExtra(“MSG”, AppConstant.PlayerMsg.CONTINUE_MSG);

startService(intent);

isPause = false;

isPlaying = true;

}

break;

case R.id.previous_music: //上一首歌曲

previous_music();

break;

case R.id.next_music: //下一首歌曲

next_music();

break;

case R.id.repeat_music: //重复播放音乐

if (repeatState == isNoneRepeat) {

repeat_one();

shuffleBtn.setClickable(false); //是随机播放变为不可点击状态

repeatState = isCurrentRepeat;

} else if (repeatState == isCurrentRepeat) {

repeat_all();

shuffleBtn.setClickable(false);

repeatState = isAllRepeat;

} else if (repeatState == isAllRepeat) {

repeat_none();

shuffleBtn.setClickable(true);

repeatState = isNoneRepeat;

}

Intent intent = new Intent(REPEAT_ACTION);

switch (repeatState) {

case isCurrentRepeat: // 单曲循环

repeatBtn

.setBackgroundResource(R.drawable.repeat_current_selector);

Toast.makeText(PlayerActivity.this, R.string.repeat_current,

Toast.LENGTH_SHORT).show();

intent.putExtra(“repeatState”, isCurrentRepeat);

sendBroadcast(intent);

break;

case isAllRepeat: // 全部循环

repeatBtn

.setBackgroundResource(R.drawable.repeat_all_selector);

Toast.makeText(PlayerActivity.this, R.string.repeat_all,

Toast.LENGTH_SHORT).show();

intent.putExtra(“repeatState”, isAllRepeat);

sendBroadcast(intent);

break;

case isNoneRepeat: // 无重复

repeatBtn

.setBackgroundResource(R.drawable.repeat_none_selector);

Toast.makeText(PlayerActivity.this, R.string.repeat_none,

Toast.LENGTH_SHORT).show();

intent.putExtra(“repeatState”, isNoneRepeat);

break;

}

break;

case R.id.shuffle_music: //随机播放状态

Intent shuffleIntent = new Intent(SHUFFLE_ACTION);

if (isNoneShuffle) { //如果当前状态为非随机播放,点击按钮之后改变状态为随机播放

shuffleBtn

.setBackgroundResource(R.drawable.shuffle_selector);

Toast.makeText(PlayerActivity.this, R.string.shuffle,

Toast.LENGTH_SHORT).show();

isNoneShuffle = false;

isShuffle = true;

shuffleMusic();

repeatBtn.setClickable(false);

shuffleIntent.putExtra(“shuffleState”, true);

sendBroadcast(shuffleIntent);

} else if (isShuffle) {

shuffleBtn

.setBackgroundResource(R.drawable.shuffle_none_selector);

Toast.makeText(PlayerActivity.this, R.string.shuffle_none,

Toast.LENGTH_SHORT).show();

isShuffle = false;

isNoneShuffle = true;

repeatBtn.setClickable(true);

shuffleIntent.putExtra(“shuffleState”, false);

sendBroadcast(shuffleIntent);

}

break;

}

}

}

/**

  • 实现监听Seekbar的类

  • @author wwj

*/

private class SeekBarChangeListener implements OnSeekBarChangeListener {

@Override

public void onProgressChanged(SeekBar seekBar, int progress,

boolean fromUser) {

if(fromUser) {

audioTrackChange(progress); //用户控制进度的改变

}

}

@Override

public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override

public void onStopTrackingTouch(SeekBar seekBar) {

}

}

/**

  • 播放音乐

*/

public void play() {

//开始播放的时候为顺序播放

repeat_none();

Intent intent = new Intent();

intent.setAction(“com.wwj.media.MUSIC_SERVICE”);

intent.putExtra(“url”, url);

intent.putExtra(“listPosition”, listPosition);

intent.putExtra(“MSG”, flag);

startService(intent);

}

/**

  • 随机播放

*/

public void shuffleMusic() {

Intent intent = new Intent(CTL_ACTION);

intent.putExtra(“control”, 4);

sendBroadcast(intent);

}

public void audioTrackChange(int progress) {

Intent intent = new Intent();

intent.setAction(“com.wwj.media.MUSIC_SERVICE”);

intent.putExtra(“url”, url);

intent.putExtra(“listPosition”, listPosition);

if(isPause) {

intent.putExtra(“MSG”, AppConstant.PlayerMsg.PAUSE_MSG);

}

else {

intent.putExtra(“MSG”, AppConstant.PlayerMsg.PROGRESS_CHANGE);

}

intent.putExtra(“progress”, progress);

startService(intent);

}

/**

  • 单曲循环

*/

public void repeat_one() {

Intent intent = new Intent(CTL_ACTION);

intent.putExtra(“control”, 1);

sendBroadcast(intent);

}

/**

  • 全部循环

*/

public void repeat_all() {

Intent intent = new Intent(CTL_ACTION);

intent.putExtra(“control”, 2);

sendBroadcast(intent);

}

/**

  • 顺序播放

*/

public void repeat_none() {

Intent intent = new Intent(CTL_ACTION);

intent.putExtra(“control”, 3);

sendBroadcast(intent);

}

/**

  • 上一首

*/

public void previous_music() {

playBtn.setBackgroundResource(R.drawable.play_selector);

listPosition = listPosition - 1;

if(listPosition >= 0) {

Mp3Info mp3Info = mp3Infos.get(listPosition); //上一首MP3

musicTitle.setText(mp3Info.getTitle());

musicArtist.setText(mp3Info.getArtist());

url = mp3Info.getUrl();

Intent intent = new Intent();

intent.setAction(“com.wwj.media.MUSIC_SERVICE”);

intent.putExtra(“url”, mp3Info.getUrl());

intent.putExtra(“listPosition”, listPosition);

intent.putExtra(“MSG”, AppConstant.PlayerMsg.PRIVIOUS_MSG);

startService(intent);

}

else {

Toast.makeText(PlayerActivity.this, “没有上一首了”, Toast.LENGTH_SHORT).show();

}

}

/**

  • 下一首

*/

public void next_music() {

playBtn.setBackgroundResource(R.drawable.play_selector);

listPosition = listPosition + 1;

if(listPosition <= mp3Infos.size() - 1) {

Mp3Info mp3Info = mp3Infos.get(listPosition);

url = mp3Info.getUrl();

musicTitle.setText(mp3Info.getTitle());

musicArtist.setText(mp3Info.getArtist());

Intent intent = new Intent();

intent.setAction(“com.wwj.media.MUSIC_SERVICE”);

intent.putExtra(“url”, mp3Info.getUrl());

intent.putExtra(“listPosition”, listPosition);

intent.putExtra(“MSG”, AppConstant.PlayerMsg.NEXT_MSG);

startService(intent);

} else {

Toast.makeText(PlayerActivity.this, “没有下一首了”, Toast.LENGTH_SHORT).show();

}

}

/**

  • 用来接收从service传回来的广播的内部类

  • @author wwj

*/

public class PlayerReceiver extends BroadcastReceiver {

@Override

public void onReceive(Context context, Intent intent) {

String action = intent.getAction();

if(action.equals(MUSIC_CURRENT)) {

currentTime = intent.getIntExtra(“currentTime”, -1);

currentProgress.setText(MediaUtil.formatTime(currentTime));

music_progressBar.setProgress(currentTime);

} else if(action.equals(MUSIC_DURATION)) {

int duration = intent.getIntExtra(“duration”, -1);

music_progressBar.setMax(duration);

finalProgress.setText(MediaUtil.formatTime(duration));

} else if(action.equals(UPDATE_ACTION)) {

//获取Intent中的current消息,current代表当前正在播放的歌曲

listPosition = intent.getIntExtra(“current”, -1);

url = mp3Infos.get(listPosition).getUrl();

if(listPosition >= 0) {

musicTitle.setText(mp3Infos.get(listPosition).getTitle());

musicArtist.setText(mp3Infos.get(listPosition).getArtist());

}

if(listPosition == 0) {

finalProgress.setText(MediaUtil.formatTime(mp3Infos.get(listPosition).getDuration()));

playBtn.setBackgroundResource(R.drawable.pause_selector);

isPause = true;

最后

以前一直是自己在网上东平西凑的找,找到的东西也是零零散散,很多时候都是看着看着就没了,时间浪费了,问题却还没得到解决,很让人抓狂。

后面我就自己整理了一套资料,还别说,真香!

资料有条理,有系统,还很全面,我不方便直接放出来,大家可以先看看有没有用得到的地方吧。

系列教程图片

2020Android复习资料汇总.png

flutter

NDK

设计思想开源框架

微信小程序

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

;

isPause = true;

最后

以前一直是自己在网上东平西凑的找,找到的东西也是零零散散,很多时候都是看着看着就没了,时间浪费了,问题却还没得到解决,很让人抓狂。

后面我就自己整理了一套资料,还别说,真香!

资料有条理,有系统,还很全面,我不方便直接放出来,大家可以先看看有没有用得到的地方吧。

[外链图片转存中…(img-SSwvRwUJ-1715592956937)]

[外链图片转存中…(img-BFYLE72Z-1715592956937)]

[外链图片转存中…(img-CLlyl6xo-1715592956938)]

[外链图片转存中…(img-fp7pHbli-1715592956938)]

[外链图片转存中…(img-JoZUGAsk-1715592956938)]

[外链图片转存中…(img-FzRXqOle-1715592956938)]

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 27
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值