當前位置:首頁 » 操作系統 » 簡單音樂源碼

簡單音樂源碼

發布時間: 2023-06-04 22:37:29

1. 求一個c#音樂播放器源代碼。

其實很簡單的,自己就可以使用Media palyer組件寫一個。
方法如下:
1,在工具箱空白處右鍵,選擇「選擇項」。
2,在com組件中選擇 「windows media player"
3,然後就可以通過 player對象來控制播放,暫停,快進等。

給你貼了參考資料鏈接。我也寫過一個播放器,支持基本的播放功能及歌詞同步,如果有需要可以把源碼發你。

2. 誰能給我一個簡單ASP音樂網源碼帶後台並可以上傳添加歌,專輯圖片等,真的急著需要各位的幫助

看下這個小系統能否滿足你埋和孝的要求,可以播放音樂並支彎稿持分享棚歷,評論。

3. 基於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();
}
}
}

4. android在線本地音樂播放器 簡單點能看懂的 誰有源碼給一個啊

下面這個例子是使用service和broadcastReceiver實現的簡單音樂播放器,麻雀雖小,五臟俱全,網路搜索安卓無憂,點擊源碼看源碼,你看演示:

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;
}
}
}
}


最後,您覺得回答滿意的話,請關注一下我的微博,我的名字除了中文以外的。

5. android 添加背景音樂源碼

一張你從伍跡手未填寫過的巨額支票,
枯黃萎縮州旦的敗葉,
不要去做,孩子
浪來時,你指著海洋彼岸
也會讓有些人感到煩擾。
他腔嫌來的這中,哈哈

6. 誰能給我幾首51單片機流行歌曲 的源代碼!

<!--[if !supportLists]-->2. <!--[endif]-->程序代碼:(以下代碼奏出八月桂花香這首曲子) ORG 0000H LJMP START ORG 000BH INC 20H ;中斷服務,中斷計數器加1 MOV TH0, #0DBH MOV TL0, #0FFH ;11.0592M晶振,形成10毫秒中斷 RETISTART: MOV SP, #50H MOV TH0, #0DBH MOV TL0, #0FFH MOV TMOD, #01H MOV IE, #82HMUSIC0: NOP MOV DPTR, #DAT ;表頭地址送DPTR MOV 20H, #00H ;中斷計數器清0MUSIC1: NOP CLR A ;A清零 MOVC A, @A+DPTR ;查表取代碼 JZ END0 ;是00H,則結束 CJNE A, #0FFH, MUSIC5 ;如果不是休止符,往下執行,;以R6作為音符頻率控制,唱R7節拍那麼久。 LJMP MUSIC3MUSIC5: NOP MOV R6, A ;R6=18H音符的頻率 INC DPTR ;DPTR加1 MOV A, #0 MOVC A, @A+DPTR ;取節拍代碼送R7 MOV R7,A ;R7=30H音符發音的時間 SETB TR0 ;啟動計數MUSIC2: NOP CPL P3.2 ;P3.2是音樂輸出引腳 MOV A, R6 MOV R3, A ;R3=R6=18H LCALL DEL MOV A, R7 CJNE A, 20H, MUSIC2 ;中斷計數器(20H)=R7否?;不等,則繼續循環 MOV 20H, #00H ;等於,則取下一代碼 INC DPTR LJMP MUSIC1MUSIC3: NOP ;休止100毫秒 CLR TR0 MOV R2, #0DH ;R2=13MUSIC4: NOP MOV R3, #0FFH ;R3=255 LCALL DEL DJNZ R2, MUSIC4 INC DPTR LJMP MUSIC1END0: NOP MOV R2, #0FFH ;歌曲結束,延時1秒後繼續MUSIC6: MOV R3, #00H LCALL DEL DJNZ R2, MUSIC6 LJMP MUSIC0DEL: NOPDEL3: MOV R4, #02H DEL4: NOP DJNZ R4, DEL4 NOP DJNZ R3, DEL3 RET NOPDAT:DB 18H, 30H, 1CH, 10H, 20H, 40H, 1CH, 10HDB 18H, 10H, 20H, 10H, 1CH, 10H, 18H, 40HDB 1CH, 20H, 20H, 20H, 1CH, 20H, 18H, 20HDB 20H, 80H, 0FFH, 20H,30H, 1CH, 10H, 18HDB 20H, 15H, 20H, 1CH, 20H, 20H, 20H, 26HDB 40H, 20H, 20H, 2BH, 20H, 26H, 20H, 20HDB 20H, 30H, 80H, 0FFH,20H, 20H, 1CH, 10HDB 18H, 10H, 20H, 20H, 26H, 20H, 2BH, 20HDB 30H, 20H, 2BH, 40H, 20H, 20H, 1CH, 10HDB 18H, 10H, 20H, 20H, 26H, 20H, 2BH, 20HDB 30H, 20H, 2BH, 40H, 20H, 30H, 1CH, 10HDB 18H, 20H, 15H, 20H, 1CH, 20H, 20H, 20HDB 26H, 40H, 20H, 20H, 2BH, 20H, 26H, 20HDB 20H, 20H, 30H, 80H, 20H, 30H, 1CH, 10HDB 20H, 10H, 1CH, 10H, 20H, 20H, 26H, 20HDB 2BH, 20H, 30H, 20H, 2BH, 40H, 20H, 15HDB 1FH, 05H, 20H, 10H, 1CH, 10H, 20H, 20HDB 26H, 20H, 2BH, 20H, 30H, 20H, 2BH, 40HDB 20H, 30H, 1CH, 10H, 18H, 20H, 15H, 20HDB 1CH, 20H, 20H, 20H, 26H, 40H, 20H, 20HDB 2BH, 20H, 26H, 20H, 20H, 20H, 30H, 30HDB 20H, 30H, 1CH, 10H, 18H, 40H, 1CH, 20HDB 20H, 20H, 26H, 40H, 13H, 60H, 18H, 20HDB 15H, 40H, 13H, 40H, 18H, 80H, 00HEND

7. c語言寫音樂,我要一個准確的源代碼,謝謝

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>

unsigned frequency[100];
char hight[100];
unsigned time[100];
unsigned rate;

void main()
{
void set(unsigned f[],char h[],unsigned t[],int r,int num);
void music(unsigned f[],unsigned t[],int num);
int flag=0;
FILE *f1;
int i,n,menu;
char FileName[30];
while(1)
{ f1=NULL;
i=n=0;

printf("本程序採用編碼的形式播放音樂。\n");
printf("\n用記事本編輯樂譜,然後通過輸入文件名播放音樂\n");
printf("樂譜文件可以自創,也可以抄別人的\n");
printf("\n現在可以先輸入數字再按回車播放音樂:\n");
printf("1 播放指定音樂music1\n");
printf("2 播放指定音樂music2\n");
printf("3 通過程序文件名播放音樂\n");
printf("4 退出\n");

while(1)
{
printf("menu=");scanf("%d",&menu);
if(menu==1)
{
strcpy(FileName,"music1.txt");
break;
}
if(menu==2)
{
strcpy(FileName,"music2.txt");
break;
}
if(menu==3)
{
scanf("%s",FileName);
break;
}
if(menu==4)
exit(0);
}

printf("\n該文件的音樂編碼如下:\n");

if((f1=fopen(FileName,"r"))==NULL)
{
printf("不能打開文件!\n");
exit(1);
}

fscanf(f1,"%d",&rate);

while(!feof(f1)&&flag!=1)
{
fscanf(f1," %d%c%d",&frequency[i],&hight[i],&time[i]);
printf(" %d%c%d",frequency[i],hight[i],time[i]);

if(time[i]!=-1)
{
i++;n++;
}
else
flag=1;

}
printf("\n");

set(frequency,hight,time,rate,n);

music(frequency,time,n);
fclose(f1);
}

getch();
}

void set(unsigned f[],char h[],unsigned t[],int r,int num)
{
int i,k;
for(i=0;i<num;i++)
{
t[i]=t[i]*r;

switch(h[i])
{
case 'H':k=4;break;
case 'M':k=2;break;
case 'L':k=1;
}

switch(f[i])
{
case 1: f[i]=262*k; break;
case 2: f[i]=296*k; break;
case 3: f[i]=330*k; break;
case 4: f[i]=349*k; break;
case 5: f[i]=392*k; break;
case 6: f[i]=440*k; break;
case 7: f[i]=494*k; break;
}
}
}

void music(unsigned f[],unsigned t[],int num)
{
int i;
for(i=0;i<num;i++)
{
Beep(f[i],t[i]);
}
}

熱點內容
出售lol腳本防封判幾年 發布:2024-04-19 12:45:14 瀏覽:187
安卓電視會員和平板哪個好 發布:2024-04-19 12:42:48 瀏覽:834
雲伺服器2m寬是多少 發布:2024-04-19 11:56:36 瀏覽:728
android層布局 發布:2024-04-19 11:52:13 瀏覽:771
1500元組裝伺服器電腦 發布:2024-04-19 11:47:25 瀏覽:469
qq改密碼怎麼改手機 發布:2024-04-19 11:39:17 瀏覽:969
電腦上如何看wifi密碼 發布:2024-04-19 11:34:14 瀏覽:416
java性能測試腳本 發布:2024-04-19 11:25:24 瀏覽:981
存儲成本與性能 發布:2024-04-19 11:16:18 瀏覽:169
linux根文件系統製作 發布:2024-04-19 11:16:12 瀏覽:747