安卓音乐播放器开源源码(android开源播放器)
本文目录一览:
- 1、Android开发,简单的音乐播放器的完整代码,含布局的。
- 2、基于Android音乐播放器源代码(正常播放、有列表)
- 3、求音乐播放器源代码,用高级语言编写即可,java/c/c++/vc都行
- 4、Android 简单音乐播放器代码(不用连接数据库)
- 5、最近在看android音乐播放器的源码,发现播放音乐等操作都是用service来进行的,这样做有什么好处?求解
- 6、求哪位大神帮我把我这安卓音乐播放器的所有代码注释下,详细点的,我毕设要用,厚礼感谢
Android开发,简单的音乐播放器的完整代码,含布局的。
手机设为离线模式不是无法定位安卓音乐播放器开源源码,而是需要较长的时间安卓音乐播放器开源源码,导航时手机会寻找卫星安卓音乐播放器开源源码,但是安卓音乐播放器开源源码,如果没有辅助定位(A-GPS)的帮助,它会浪费很多时间去找合适的卫星,而使用A-GPS就需要通讯网络的支持,它能够先计算你所在的大概位置,然后就有针对性地搜索卫星,快很多。
而车载导航仪就属于专业、专门的设备,接收能力和功率等硬件设计都可以使其很方便和很专业地搜索卫星,即使卫星信号不太好,也能搜得到。它们的工作原理大致相同,只是功率和所使用的软件不同
基于Android音乐播放器源代码(正常播放、有列表)
package my.android.players;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;
public class mainActivity extends Activity {
private ListString myMusicList=new ArrayListString();
//当前播放歌曲的索引
private int currentListItem=0;
//音乐的路径
private static final String MUSIC_PATH="/sdcard/mp3";
//播放对象
private MediaPlayer myMediaPlayer;
private TextView m_TextView;
//播放按钮
private ImageButton m_start;
private ImageButton m_stop;
private ImageButton m_next;
private ImageButton m_last;
/*设定bIsPaused一开始为false */
private boolean bIsRun = false;
private boolean isplay;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main2);
myMediaPlayer=new MediaPlayer();
musicList();
m_TextView=(TextView)findViewById(R.id.mtextview);
m_start=(ImageButton)findViewById(R.id.imgbtn_start);
m_stop=(ImageButton)findViewById(R.id.imgbtn_stop);
m_next=(ImageButton)findViewById(R.id.imgbtn_next);
m_last=(ImageButton)findViewById(R.id.imgbtn_last);
listener();
Intent intent = this.getIntent();
Bundle bundle = intent.getExtras();
currentListItem = bundle.getInt("currentListItem");
isplay=bundle.getBoolean("isplay");
if(isplay==true)
{
bIsRun=false;
playMusic(MUSIC_PATH+"/"+myMusicList.get(currentListItem));
}
}
//监听事件
void listener(){
//开始
m_start.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try
{
if(myMediaPlayer.isPlaying()==true)
{
myMediaPlayer.pause();
m_start.setImageResource(R.drawable.pause);
}
else
{
playMusic(MUSIC_PATH+"/"+myMusicList.get(currentListItem));
}
}
catch (IllegalStateException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
//下一首
m_next.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
nextMusic();
}
});
//上一首
m_last.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
lastMusic();
}
});
//停止
m_stop.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
stopMusic();
}
});
myMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
nextMusic();
}
});
}
//播放音乐
void playMusic(String path){
try {
if(bIsRun==false)
{
myMediaPlayer.reset();
myMediaPlayer.setDataSource(path);
myMediaPlayer.prepare();
myMediaPlayer.start();
/*
* 取出歌曲名的.mp3后缀
* */
String str=(myMusicList.get(currentListItem)).toString();
System.out.println(str);
String str1[]=str.split("\\.");
System.out.println(str1[0]);
m_TextView.setText(str1[0]);
}
else
{
myMediaPlayer.start();
}
m_start.setImageResource(R.drawable.start);
bIsRun=true;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
//下一首
void nextMusic(){
if(++currentListItem=myMusicList.size()){
currentListItem=0;
}
bIsRun=false;
playMusic(MUSIC_PATH+"/"+myMusicList.get(currentListItem));
}
//上一首
void lastMusic(){
if(--currentListItem0)
currentListItem=myMusicList.size()-1;
bIsRun=false;
playMusic(MUSIC_PATH+"/"+myMusicList.get(currentListItem));
}
//停止
void stopMusic() {
if (myMediaPlayer.isPlaying()) {
m_start.setImageResource(R.drawable.pause);
myMediaPlayer.stop();// 停止
bIsRun=false;
}
else
playMusic(MUSIC_PATH+"/"+myMusicList.get(currentListItem));
}
//当用户返回时结束音乐并释放音乐对象
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if(keyCode==KeyEvent.KEYCODE_BACK){
new AlertDialog.Builder(mainActivity.this).setTitle("message")
.setIcon(android.R.drawable.dialog_frame)
.setMessage("你确定要离开吗?")
.setPositiveButton("确定",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
myMediaPlayer.stop();
myMediaPlayer.release();
finish();
}
}).setNegativeButton("取消",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
return super.onKeyDown(keyCode, event);
}
/**
* 文件过滤器
*
* @author
*
*/
class MusicFilter implements FilenameFilter {
@Override
public boolean accept(File dir, String filename) {
return (filename.endsWith(".mp3"));
}
}
//绑定音乐
void musicList(){
try{
File home=new File(MUSIC_PATH);
if(!home.exists())
home.mkdirs();
if(home.listFiles(new MusicFilter()).length=0){
for(File file:home.listFiles(new MusicFilter())){
myMusicList.add(file.getName().toString());
}
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
package my.android.players;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Activity01 extends Activity {
//播放列表
private ListString myMusicList=new ArrayListString();
//当前播放歌曲的索引
private int currentListItem;
//音乐的路径
private static final String MUSIC_PATH="/sdcard/mp3";
//播放列表
private ListView m_ListView;
private boolean isplay=true;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
m_ListView=(ListView)findViewById(R.id.lv_music);
musicList();
//当选择列表项时播放音乐
m_ListView.setOnItemClickListener(new ListView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView? arg0, View arg1, int arg2,
long arg3) {
currentListItem = arg2;
Intent intent = new Intent();
Bundle mBundle=new Bundle();
mBundle.putInt("currentListItem", currentListItem);
mBundle.putBoolean("isplay", isplay);
intent.putExtras(mBundle);
intent.setClass(Activity01.this,mainActivity.class);
startActivity(intent);
finish();
}
});
}
/**
* 文件过滤器
*
* @author
*
*/
class MusicFilter implements FilenameFilter {
@Override
public boolean accept(File dir, String filename) {
return (filename.endsWith(".mp3"));
}
}
//绑定音乐
void musicList(){
try{
File home=new File(MUSIC_PATH);
if(!home.exists())
home.mkdirs();
if(home.listFiles(new MusicFilter()).length=0){
for(File file:home.listFiles(new MusicFilter())){
myMusicList.add(file.getName().toString());
}
ArrayAdapterString musicList=new ArrayAdapterString
(Activity01.this,android.R.layout.simple_list_item_1, myMusicList);
m_ListView.setAdapter(musicList);
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
求音乐播放器源代码,用高级语言编写即可,java/c/c++/vc都行
我这里有我自己做的MP3播放器,是用c#做的。
我已经发给你了!
Android 简单音乐播放器代码(不用连接数据库)
代码太长。。给出部分代码,具体的 看附件 ,可以直接导入运行
/**
* 上一首
*/
public void pree(){
int n_index = currIndex;
n_index--;
if(filelist == null){
return;
}
if (n_index 0) {
n_index = filelist.length - 1;
}
currIndex = n_index;
play(filelist[n_index].getPath());
}
/**
* 下一首
* @param path
*/
public void next(){
int n_index = currIndex;
n_index++;
if(filelist == null){
return;
}
if (n_index = filelist.length) {
n_index = 0;
}
n_index = (int) (System.currentTimeMillis() % filelist.length);
currIndex = n_index;
play(filelist[n_index].getPath());
}
public void setLiveView(String path) {
filelist = getList(path);
String[] data = new String[filelist.length];
for (int i = 0; i = filelist.length - 1; i++) {
data[i] = filelist[i].getPath();
}
// 绑定ListView和ArrayAdapter
lv_list.setAdapter(new ArrayAdapterString(this,
android.R.layout.simple_list_item_1, data));
// 添加点击
lv_list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView? arg0, View v, int arg2,
long arg3) {
setTitle(filelist[arg2].getName());
currIndex = arg2;
play(filelist[arg2].getPath());
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (FILE_RESULT_CODE == requestCode) {
Bundle bundle = null;
if (data != null (bundle = data.getExtras()) != null) {
// bundle.getString("file");
// setTitle(bundle.getString("file"));
setLiveView(bundle.getString("file"));
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public File[] getList(String filepath) {
File file = new File(filepath);
File[] filelist = file.listFiles();
return filelist;
}
public void play(String filepath) {
mediaPlayer.reset();
if (mediaPlayer.isPlaying()) {
mediaPlayer.reset();// 重置为初始状态
}
try {
mediaPlayer.setDataSource(filepath);// "/storage/extSdCard/My Music"
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mediaPlayer.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// mediaPlayer.release();
mediaPlayer.start();// 开始或恢复播放
bt_zan.setText("开始");
isstop = false;
// mediaPlayer.pause();//暂停播放
// mediaPlayer.start();//恢复播放
// mediaPlayer.stop();//停止播放
// mediaPlayer.release();//释放资源
mediaPlayer
.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {// 播出完毕事件
@Override
public void onCompletion(MediaPlayer arg0) {
// mediaPlayer.release();
if(mode == 1){ // 顺序播放
next();
}
else if(mode == 2){ //随机播放
// double ran = Math.random();// filelist.length;
// ran = ran * filelist.length;
// int ran = Time.SECOND % filelist.length;
next();
}
else{
next();
}
}
});
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {// 错误处理事件
@Override
public boolean onError(MediaPlayer player, int arg1,
int arg2) {
mediaPlayer.release();
return false;
}
});
}
最近在看android音乐播放器的源码,发现播放音乐等操作都是用service来进行的,这样做有什么好处?求解
首先service安卓音乐播放器开源源码的启动方式有两种,Context.startService()方式启动和Context.bindService()方式启动.前者如果安卓音乐播放器开源源码你的程序退出时不停止Service,它会在后台一直运行.后者是跟你的程序绑定了,你的程序退出时Service也停止了.详细的你去查一下.用Service的好处就是当你的程序进入后台时,不影响音乐的播放.如果没有把播放音乐写在Service中当你的播放器进入后台或者退出时音乐就停止了.
求哪位大神帮我把我这安卓音乐播放器的所有代码注释下,详细点的,我毕设要用,厚礼感谢
在manifest.xml中加上几句,,具体什么我忘了,你看看android源码里的播放器的manifest.xml里写的就知道了
你下个开源的android播放器,然后看看他的manifest.xml,