package com.gem.music;
import java.util.ArrayList;
import java.util.List;
import com.gem.Utils.Music;
import com.gem.music.R;
import com.gem.tools.SetListDataForOur;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;
@SuppressLint({ "HandlerLeak", "ShowToast", "DefaultLocale" })
public class MusicActivity extends Activity implements OnSeekBarChangeListener,
MediaPlayer.OnErrorListener, Runnable {
public static MediaPlayer player = null;
private TextView textName;
private TextView textSinger;
private TextView textStartTime;
private TextView textEndTime;
private SeekBar seekBar1;
@SuppressWarnings("unused")
private ImageView icon;
private ImageButton imageBtnLast;
private ImageButton imageBtnRewind;
private ImageButton imageBtnPlay;
private ImageButton imageBtnForward;
private ImageButton imageBtnNext;
private ImageButton imageBtnLoop;
private ImageButton imageBtnRandom;
private boolean isLoop = false;
public static int _id = -1;
@SuppressWarnings("unused")
private int cruID = -1;
private List<Music> lists;
private AudioManager audioManager;// 音量管理者
private int maxVolume;// 最大音量
private int currentVolume;// 当前音量
private SeekBar seekBarVolume;// 进度条
private Cursor cursor;
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
int position = msg.what;// 获取handler 跳转位置
int total = player.getDuration();
int progress = position * 100 / total;
textStartTime.setText(toTime(position));
seekBar1.setProgress(progress);
super.handleMessage(msg);
}
};
/*****
* 该方法,调用的是,显示的时间的功能
*
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.music);
textName = (TextView) this.findViewById(R.id.music_name);
textSinger = (TextView) this.findViewById(R.id.music_singer);
textStartTime = (TextView) this.findViewById(R.id.music_start_time);
textEndTime = (TextView) this.findViewById(R.id.music_end_time);
seekBar1 = (SeekBar) this.findViewById(R.id.music_seekBar);
icon = (ImageView) this.findViewById(R.id.image_icon);
imageBtnLast = (ImageButton) this.findViewById(R.id.music_lasted);
imageBtnRewind = (ImageButton) this.findViewById(R.id.music_rewind);
imageBtnPlay = (ImageButton) this.findViewById(R.id.music_play);
imageBtnForward = (ImageButton) this.findViewById(R.id.music_foward);
imageBtnNext = (ImageButton) this.findViewById(R.id.music_next);
imageBtnLoop = (ImageButton) this.findViewById(R.id.music_loop);
seekBarVolume = (SeekBar) this.findViewById(R.id.music_volume);
imageBtnRandom = (ImageButton) this.findViewById(R.id.music_random);
setListData();
imageBtnLast.setOnClickListener(new MyListener());
imageBtnRewind.setOnClickListener(new MyListener());
imageBtnPlay.setOnClickListener(new MyListener());
imageBtnForward.setOnClickListener(new MyListener());
imageBtnNext.setOnClickListener(new MyListener());
imageBtnLoop.setOnClickListener(new MyListener());
imageBtnRandom.setOnClickListener(new MyListener());
seekBar1.setOnSeekBarChangeListener(this);// 监听进度条时所用
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);// 获得最大音量
currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);// 获得当前音量
seekBarVolume.setMax(maxVolume);
seekBarVolume.setProgress(currentVolume);
seekBarVolume.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,
progress, AudioManager.FLAG_ALLOW_RINGER_MODES);
}
});
}
@SuppressWarnings("deprecation")
@Override
protected void onStart() {
// TODO Auto-generated method stub
int id = getIntent().getIntExtra("id", 1);
Music m = lists.get(id);
SongsActivity.listMusic.add(m);
textName.setText(m.getTitle());
textSinger.setText(m.getSinger());
textEndTime.setText(toTime((int) m.getTime()));
imageBtnPlay.setImageResource(R.drawable.pause1);
if (id != _id) {
_id = id;
if (player != null) {
if (player.isPlaying()) {
player.release();
player = null;
}
}
String url = m.getUrl();
Uri myUri = Uri.parse(url);
player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setWakeMode(this, PowerManager.PARTIAL_WAKE_LOCK);
try {
player.setDataSource(getApplicationContext(), myUri);
player.prepare();
} catch (Exception e) {
e.printStackTrace();
}
player.start();
// PendingIntent主要持有的信息是它所包装的Intent和当前Application的Context,
// 正由于PendingIntent中保存有当前Application的Context,使它赋予带他程序一种执行的Intent的能力,
// 就算在执行时当前Application已经不存在了,也能通过存在PendingIntent里的Context照样执行Intent。
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);// 获取通知管理器
int icon = R.drawable.play1;
CharSequence tickerText = "正在播放音乐 . . . ";
long when = System.currentTimeMillis();// 通知发生的时间为系统当前时间
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "正在播放音乐 . . . ";
CharSequence contentText = "";
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);// 当点击消息时就会向系统发送openintent意图
notification.setLatestEventInfo(context, contentTitle, contentText,
contentIntent);// contentIntent,它是PendingIntent中最重要的一个参数,是为了发射意图
mNotificationManager.notify(1, notification);
}
if (player != null) {
player.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// 下一首
player.reset();
if (isLoop == true) {
_id = _id - 1;
}
forward();
}
});
}
new Thread(this).start();
super.onStart();// 调用当前 方法
}
// 图片按钮功能区的实现
private class MyListener implements OnClickListener {
@Override
public void onClick(View v) {
if (v == imageBtnLast) {
// 第一首
player.release();
player = null;
first();// 通过内部类实现
} else if (v == imageBtnRewind) {
// 前一首
player
没有合适的资源?快使用搜索试试~ 我知道了~
音乐播放器_20140702153506.zip项目安卓应用源码下载
共125个文件
png:64个
class:30个
xml:12个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 103 浏览量
2022-03-09
11:03:48
上传
评论
收藏 1.45MB ZIP 举报
温馨提示
音乐播放器_20140702153506.zip项目安卓应用源码下载音乐播放器_20140702153506.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考
资源推荐
资源详情
资源评论
收起资源包目录
音乐播放器_20140702153506.zip项目安卓应用源码下载 (125个子文件)
resources.ap_ 339KB
music_player1.apk 355KB
media_music.bmp 254KB
jarlist.cache 120B
MusicActivity.class 13KB
ItemActivity.class 3KB
AlbumsActivity.class 3KB
MainActivity.class 3KB
SetListDataForOur.class 3KB
ItemActivity$MusicItemAdapter.class 2KB
ArtistActivity$MusicItemAdapter.class 2KB
ArtistActivity.class 2KB
AlbumsActivity$MusicItemAdapter.class 2KB
SongsActivity$MusicItemAdapter.class 2KB
MusicActivity$MyListener.class 2KB
Music.class 2KB
ArtistActivity$1.class 1KB
AlbumsActivity$1.class 1KB
ItemActivity$1.class 1KB
R$drawable.class 1KB
SongsActivity.class 1KB
MusicActivity$1.class 1KB
MusicActivity$2.class 1KB
R$id.class 1KB
MusicActivity$3.class 979B
MusicActivity$6.class 979B
MusicActivity$5.class 978B
MusicActivity$4.class 977B
MusicActivity$7.class 976B
R$layout.class 557B
R.class 496B
R$string.class 412B
BuildConfig.class 335B
R$attr.class 325B
.classpath 491B
classes.dex 28KB
MusicActivity.java 15KB
ItemActivity.java 4KB
R.java 4KB
AlbumsActivity.java 3KB
ArtistActivity.java 3KB
MainActivity.java 2KB
SongsActivity.java 2KB
SetListDataForOur.java 2KB
Music.java 1KB
BuildConfig.java 155B
player_bg.png 142KB
player_bg.png 101KB
playbg.png 63KB
playbg.png 48KB
listbg.png 41KB
listbg.png 38KB
music.png 29KB
music.png 29KB
music.png 29KB
music.png 26KB
music.png 26KB
music.png 26KB
tabs_btn.png 24KB
appbg.png 18KB
tabs_btn.png 17KB
appbg.png 12KB
ic_launcher.png 4KB
ic_launcher.png 4KB
play_loop_spec.png 4KB
item.png 4KB
isplaying.png 4KB
latest1.png 4KB
next1.png 4KB
play1.png 4KB
pause1.png 3KB
play_loop_sel.png 3KB
play_loop.png 3KB
play.png 3KB
play_random_sel.png 3KB
next.png 3KB
latest.png 3KB
foward.png 3KB
rewind.png 3KB
pause.png 3KB
play_random.png 3KB
icon.png 3KB
icon.png 2KB
media_player_progress_bg.png 2KB
media_player_progress_bg.png 2KB
media_player_progress_button.png 2KB
media_player_progress_button.png 2KB
play_loop_spec.png 1KB
album.png 1KB
isplaying.png 1KB
latest1.png 1KB
next1.png 1KB
play1.png 1KB
artist.png 1KB
album.png 1KB
item.png 1KB
artist.png 1KB
pause1.png 930B
play.png 675B
play_loop.png 474B
共 125 条
- 1
- 2
资源评论
yxkfw
- 粉丝: 81
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功