Ⅰ 基于安卓的手机音乐播放器
来比较大海汹涌的表面。
而我们吸入从船板
渗透出来的树脂的香味
赞叹整齐地铆进哈哈舱壁的木板,
不是由伯利恒那个平静的木匠而是由另一个,
那个航海之父和航海员之友铆进
它们也曾经耸立在干爽的陆地,
Ⅱ Android音乐播放器(同步显示歌词)源代码的密码是多少
去论坛看看,里面有的
Ⅲ Android音乐播放器的源码 做毕业设计用 所以要自己写的比较好 功能要实用 发我邮箱[email protected]
答案:我在屋内,他在屋外。
Ⅳ 安卓开源在线音乐播放器
在线听音乐上网,qq,反正只要和上网有关,必然会产生缓存,占用手机内存,这是不可能避免的。(如果可以人家早就开发了)网页播放器产生的所谓在线缓存跟这个实质上是一样的,其实根本不用太担心,你只要调整相应程序缓存文件的大小就OK了
Ⅳ 如何用android来做一个音乐电台,源码 代码
就是的啊 安卓的音乐电台做出来 也不会给你的啊 ,都出来了 那就是完整的软件了
Ⅵ android在线本地音乐播放器 简单点能看懂的 谁有源码给一个啊
下面这个例子是使用service和broadcastReceiver实现的简单音乐播放器,麻雀虽小,五脏俱全,网络搜索安卓无忧,点击源码看源码,你看演示:
java">packagemm.shandong.com.testsimplemedia;
importandroid.content.BroadcastReceiver;
importandroid.content.Context;
importandroid.content.Intent;
importandroid.content.IntentFilter;
importandroid.support.v7.app.AppCompatActivity;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.widget.ImageButton;
importandroid.widget.TextView;
importmm.shandong.com.testsimplemedia.service.MusicService;
{
ImageButtonimageButton;
TextViewtextViewMp3Name;
TextViewtextViewMp3Author;
intstatus=0;
String[]authors=newString[]{"张三","李四","王二"};
String[]names=newString[]{"first","second","thrid"};
intcurrentMusic=0;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_simple_media);
imageButton=(ImageButton)findViewById(R.id.imageButton);
textViewMp3Name=(TextView)findViewById(R.id.textViewMp3Name);
textViewMp3Author=(TextView)findViewById(R.id.textViewMp3Author);
imageButton.setOnClickListener(newView.OnClickListener(){
@Override
publicvoidonClick(Viewview){
Intentintent=newIntent("Get_Music_Control");
if(status==2){
intent.putExtra("control",0);
}else{
intent.putExtra("control",1);
}
sendBroadcast(intent);
}
});
IntentFilterintentFilter=newIntentFilter();
intentFilter.addAction("Update_Music_State");
=newMusicStatusReceiver();
//动态注册activity变化的广播接收者
registerReceiver(musicStatusReceiver,intentFilter);
Intentintent=newIntent(this,MusicService.class);
startService(intent);
IntentintentMusicReceiver=newIntent("Get_Music_Control");
intentMusicReceiver.putExtra("control",3);
sendBroadcast(intentMusicReceiver);
}
///上一首
publicvoidpreMusic(Viewview){
IntentintentMusicReceiver=newIntent("Get_Music_Control");
intentMusicReceiver.putExtra("control",4);
sendBroadcast(intentMusicReceiver);
}
///下一首
publicvoidnextMusic(Viewview){
IntentintentMusicReceiver=newIntent("Get_Music_Control");
intentMusicReceiver.putExtra("control",5);
sendBroadcast(intentMusicReceiver);
}
///定义操作音乐的广播接收者
{
@Override
publicvoidonReceive(Contextcontext,Intentintent){
status=intent.getIntExtra("status",0);
currentMusic=intent.getIntExtra("currentMusic",0);
switch(status){
case0:
textViewMp3Name.setText(names[currentMusic]);
textViewMp3Author.setText(authors[currentMusic]);
imageButton.setBackgroundResource(R.drawable.play32);
break;
case1:
textViewMp3Name.setText(names[currentMusic]);
textViewMp3Author.setText(authors[currentMusic]);
imageButton.setBackgroundResource(R.drawable.play32);
break;
case2:
imageButton.setBackgroundResource(R.drawable.pause32);
textViewMp3Name.setText(names[currentMusic]);
textViewMp3Author.setText(authors[currentMusic]);
break;
}
}
}
}
最后,您觉得回答满意的话,请关注一下我的微博,我的名字除了中文以外的。
Ⅶ 基于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 List<String> myMusicList=new ArrayList<String>();
//当前播放歌曲的索引
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(--currentListItem<0)
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 List<String> myMusicList=new ArrayList<String>();
//当前播放歌曲的索引
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());
}
ArrayAdapter<String> musicList=new ArrayAdapter<String>
(Activity01.this,android.R.layout.simple_list_item_1, myMusicList);
m_ListView.setAdapter(musicList);
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
Ⅷ 安卓编程添加背景音乐代码和方法
MediaPlayer
网上有人封装了一个直接拿来用就可以了
packagecom.llkan.setup;
importjava.util.HashMap;
importjava.util.Map;
importjava.util.Random;
importcom.llkan.R;
importandroid.content.Context;
importandroid.media.AudioManager;
importandroid.media.MediaPlayer;
importandroid.media.SoundPool;
/**
*声音控制类
*@authorwyf
*
*/
publicclassSoundPlayer{
privatestaticMediaPlayermusic;
;
privatestaticbooleanmusicSt=true;//音乐开关
privatestaticbooleansoundSt=true;//音效开关
privatestaticContextcontext;
privatestaticfinalint[]musicId={R.raw.bg,R.raw.bg1,R.raw.bg2,R.raw.bg3};
privatestaticMap<Integer,Integer>soundMap;//音效资源id与加载过后的音源id的映射关系表
/**
*初始化方法
*@paramc
*/
publicstaticvoidinit(Contextc)
{
context=c;
initMusic();
initSound();
}
//初始化音效播放器
privatestaticvoidinitSound()
{
soundPool=newSoundPool(10,AudioManager.STREAM_MUSIC,100);
soundMap=newHashMap<Integer,Integer>();
soundMap.put(R.raw.itemboom,soundPool.load(context,R.raw.itemboom,1));
soundMap.put(R.raw.sel,soundPool.load(context,R.raw.sel,1));
}
//初始化音乐播放器
privatestaticvoidinitMusic()
{
intr=newRandom().nextInt(musicId.length);
music=MediaPlayer.create(context,musicId[r]);
music.setLooping(true);
}
/**
*播放音效
*@paramresId音效资源id
*/
publicstaticvoidplaySound(intresId)
{
if(soundSt==false)
return;
IntegersoundId=soundMap.get(resId);
if(soundId!=null)
soundPool.play(soundId,1,1,1,0,1);
}
/**
*暂停音乐
*/
publicstaticvoidpauseMusic()
{
if(music.isPlaying())
music.pause();
}
/**
*播放音乐
*/
publicstaticvoidstartMusic()
{
if(musicSt)
music.start();
}
/**
*切换一首音乐并播放
*/
()
{
if(music!=null)
music.release();
initMusic();
startMusic();
}
/**
*获得音乐开关状态
*@return
*/
publicstaticbooleanisMusicSt(){
returnmusicSt;
}
/**
*设置音乐开关
*@parammusicSt
*/
publicstaticvoidsetMusicSt(booleanmusicSt){
SoundPlayer.musicSt=musicSt;
if(musicSt)
music.start();
else
music.stop();
}
/**
*获得音效开关状态
*@return
*/
publicstaticbooleanisSoundSt(){
returnsoundSt;
}
/**
*设置音效开关
*@paramsoundSt
*/
publicstaticvoidsetSoundSt(booleansoundSt){
SoundPlayer.soundSt=soundSt;
}
/**
*发出‘邦’的声音
*/
publicstaticvoidboom()
{
playSound(R.raw.itemboom);
}
}
还有 小编卖萌了