mp3文件播放器源代码
- 格式:doc
- 大小:36.50 KB
- 文档页数:5
Main.cpp#include <QtGui/QApplication>#include "mp3.h"#include <QTextCodec>int main(intargc, char *argv[]){QApplicationa(argc, argv);//显示中文字体QTextCodec*pCodec=QTextCodec::codecForName("System");//获取系统字体编码QTextCodec::setCodecForLocale(pCodec);QTextCodec::setCodecForCStrings(pCodec);QTextCodec::setCodecForTr(pCodec);mp3 w;w.show();returna.exec();}Mp3.cpp#include "mp3.h"#include "ui_mp3.h"#include <QFileDialog>#include <QDesktopServices>#include <QString>mp3::mp3(QWidget *parent) :QDialog(parent){//××××××××××××初始化×××××××××××××××setWindowTitle(tr("音频播放器-朱家永"));setStyleSheet("background-color:green;");//左widget=new QWidget;widget->resize(400,400);//播放音频初始化media=new Phonon::MediaObject;Phonon::AudioOutput *aOutput=newPhonon::AudioOutput(Phonon::VideoCategory);Phonon::createPath(media,aOutput);//视频vwidget=new Phonon::VideoWidget(widget);Phonon::createPath(media,vwidget);vwidget->setAspectRatio(Phonon::VideoWidget::AspectRatioAuto);//声音大小调节volumeSlider=new Phonon::VolumeSlider;volumeSlider->setAudioOutput(aOutput);volumeSlider->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum);//播放进度seekSlider=new Phonon::SeekSlider;seekSlider->setMediaObject(media);vwidget=new Phonon::VideoWidget();Phonon::createPath(media,vwidget);vwidget->setAspectRatio(Phonon::VideoWidget::AspectRatioAuto);time=new QLabel(tr("00:00"));lyricbutton=new QCheckBox(tr("歌词"));buttonup=new QPushButton;buttonup->setIcon(QIcon("./up.png"));//设置按钮的图标buttonplay_pause=new QPushButton;buttonplay_pause->setIcon(QIcon("./pause.png")); buttonstop=new QPushButton;buttonstop->setIcon(QIcon("./stop.png")); buttonnext=new QPushButton;buttonnext->setIcon(QIcon("./next.png"));palying=new QLabel(tr("正在播放:"));ge=new QLineEdit;ge->setText(tr("当前没有播放音频"));//右sou=new QLineEdit;button5=new QPushButton;button5->setIcon(QIcon("./sou.jpg"));musiclist=new QLabel(tr("歌曲列表:"));add=new QPushButton(tr("+添加"));sub=new QPushButton(tr("—删除"));lists=new QTextEdit;lists->setText(tr("列表没有音频文件,请添加"));la=new QScrollBar(Qt::Vertical);//////添加到布局/////////////////////左侧LeftGridLayout1=new QGridLayout();LeftGridLayout1->setSpacing(2);LeftGridLayout1->addWidget(seekSlider,0,0); LeftGridLayout1->addWidget(time,0,1); LeftGridLayout2=new QGridLayout();LeftGridLayout2->setSpacing(20);LeftGridLayout2->addWidget(lyricbutton,0,0); LeftGridLayout2->addWidget(buttonup,0,1); LeftGridLayout2->addWidget(buttonplay_pause,0,2);LeftGridLayout2->addWidget(buttonstop,0,3);LeftGridLayout2->addWidget(buttonnext,0,4);LeftGridLayout2->addWidget(volumeSlider,0,5);LeftGridLayout3=new QGridLayout();LeftGridLayout3->addWidget(palying,0,0);LeftGridLayout3->addWidget(ge,0,1);leftVBLayout=new QVBoxLayout();leftVBLayout->setMargin(10);leftVBLayout->addLayout(LeftGridLayout1); leftVBLayout->addLayout(LeftGridLayout2); leftVBLayout->addLayout(LeftGridLayout3); leftVBLayout->addWidget(vwidget);////右侧RightGridLayout1=new QGridLayout();RightGridLayout1->setSpacing(5);RightGridLayout1->addWidget(sou,0,0);RightGridLayout1->addWidget(button5,0,1);RightGridLayout3=new QGridLayout();RightGridLayout3->setSpacing(30);RightGridLayout3->addWidget(musiclist,0,0); RightGridLayout3->addWidget(add,0,1); RightGridLayout3->addWidget(sub,0,2); RightGridLayout2=new QGridLayout(); RightGridLayout2->setSpacing(0); RightGridLayout2->addWidget(lists,0,0); RightGridLayout2->addWidget(la,0,1); RightVBLayout=new QVBoxLayout(); RightVBLayout->setMargin(10);RightVBLayout->addLayout(RightGridLayout1); RightVBLayout->addLayout(RightGridLayout3); RightVBLayout->addLayout(RightGridLayout2);//////////主窗体////////////QGridLayout *mainLayout=new QGridLayout(this); mainLayout->setMargin(15);mainLayout->setSpacing(10);mainLayout->addLayout(leftVBLayout,0,0);mainLayout->addLayout(RightVBLayout,0,1);mainLayout->setSizeConstraint(QLayout::SetFixedSize);//设置窗口不可大小改变/////////////////////////////函数连接//////////////////////////////////////connect(buttonplay_pause,SIGNAL(clicked()),this,SLOT(play_pause())) ;//播放+暂停connect(buttonstop,SIGNAL(clicked()),this,SLOT(stopmusic()));//停止connect(add,SIGNAL(clicked()),this,SLOT(addmusic()));//添加音频文件到列表(只能添加一个.......晕)connect(sub,SIGNAL(clicked()),this,SLOT(submusic()));//从列表中删除音频文件}/////////////////////////////////////////////////////////////////// ///////void mp3::play_pause()//播放+暂停{buttonplay_pause->setIcon(QIcon("./play.png"));ge->setText(file);switch(media->state()){case Phonon::PlayingState:media->pause();buttonplay_pause->setIcon(QIcon("./pause.png")); buttonplay_pause->setChecked(false);break;case Phonon::PausedState:media->play();buttonplay_pause->setIcon(QIcon("./play.png")); break;case Phonon::StoppedState:media->play();break;case Phonon::LoadingState:buttonplay_pause->setChecked(false);break;}}void mp3::stopmusic()//停止{media->stop();buttonplay_pause->setIcon(QIcon("./pause.png"));ge->setText(tr("当前没有播放音频"));}void mp3::addmusic(){file = QFileDialog::getOpenFileName(this,"打开文件","/","music(*.mp3 *.acc *wav.);;video(.*mp4 *.avi *.rmvb)"); lists ->setText(file.toAscii());media->setCurrentSource(Phonon::MediaSource(file));}void mp3::submusic(){lists->clear();media->stop();buttonplay_pause->setIcon(QIcon("./pause.png"));file="";media->setCurrentSource(Phonon::MediaSource());//删除后,放弃该歌曲路径,需再次播放,则必须再次添加ge->setText(tr("当前没有播放音频"));}mp3::~mp3(){}Mp3.h#ifndef MP3_H#define MP3_H#include <QtGui>#include <QDialog>#include<phonon>classQProgressBar;class mp3 : public QDialog{Q_OBJECTpublic:explicit mp3(QWidget *parent = 0);~mp3();private://注意!!!使用Phonon时候,必须在工程pro中添加语句QT += phonon //左Phonon::SeekSlider *seekSlider;//播放进度QLabel *time;QGridLayout *LeftGridLayout1;QCheckBox *lyricbutton;//歌词按钮QPushButton *buttonup;//上一曲按钮QPushButton *buttonplay_pause;//播放和暂停QPushButton *buttonstop;//停止QPushButton *buttonnext;//下一曲QGridLayout *LeftGridLayout2; QLabel *palying; //正在播放(文字) QLineEdit *ge;QGridLayout *LeftGridLayout3; QVBoxLayout *leftVBLayout;//右QLineEdit *sou;QPushButton *button5;//搜索按钮QGridLayout *RightGridLayout1; QLabel *musiclist; //歌曲列表QPushButton *add;QPushButton *sub;QGridLayout *RightGridLayout3; QTextEdit *lists;QScrollBar *la;QGridLayout *RightGridLayout2;QVBoxLayout * RightVBLayout;////////////////////////////////////////////// Phonon::MediaObject *media;Phonon::VideoWidget *vwidget;QWidget *widget;Phonon::VolumeSlider *volumeSlider;//声音大小调节QString file;private slots:void play_pause();//播放+暂停void stopmusic();//停止voidaddmusic();voidsubmusic();};#endif // MP3_H。
HTML5⾃定义mp3播放器源码audio对象src兼容.ogg .wav .mp3<audio controls src='data/imooc.wav'></audio>width autoplay loop muted静⾳<audio controls src='data/imooc.wav' autoplay loop width='500' height='500' muted></audio>播放play()var myAudio = new Audio();myAudio.src = 'data/imooc.wav';myAudio.play();btn.onclick = function(){myAudio.play();};暂停pause()pauseNode.onclick = function(){myAudio.pause();};当前播放的时间currentTime⾳频总时长duration//返回⾳频的总长度myAudio.addEventListener('canplay',function(){durationNode.innerHTML = myAudio.duration;});//更新当前播放的时间setInterval(function(){currentNode.innerHTML = myAudio.currentTime;},100);⾳频源currentSrcvar myAudio = new Audio();myAudio.src = 'data/imooc.mp3';console.log(myAudio.currentSrc);loop循环myAudio.loop = true;⾳频播放结束endedmyAudio.addEventListener('ended',function(){console.log('⾳频播放结束');console.log(myAudio.ended)});重新加载loadBtn.onclick = function(){myAudio.load();};跳转到新的播放位置seeked / seekingmyAudio.addEventListener('seeked',function(){console.log('seeked');});myAudio.addEventListener('seeking',function(){console.log('seeking');sekingNum++;seekingNum.innerHTML = sekingNum;});playbackRate设置当前播放速度myAudio.playbackRate = '15';console.log(myAudio.playbackRate)全屏requestFullScreenbtnScreen.onclick = function(){myAudio.webkitRequestFullScreen();}loop 循环myAudio.loop = true;volumechange⾳量改变myAudio.addEventListener('volumechange',function(){console.log('⾳频的声⾳改变了')});timeupdate⾳频正在播放状态myAudio.addEventListener('timeupdate',function(){console.log('⾳频正在播放中...')})⾃定义mp3播放器放图<!doctype html><html><head><meta charset="utf-8"><title></title><style type="text/css">*{margin: 0;padding: 0;list-style: none;}.outerNode{width: 505px;height: 406px;position: absolute;left: 50%;top: 50%;margin: -204px 0 0 -253.5px;border: 1px solid #a6a18d;border-radius:8px;box-shadow: 0 0 16px #a6a18d; } .innerNode{width: 503px;height: 405px;border-top:1px solid #e1d1b9;border-left:1px solid #ceccbf;border-radius: 8px;overflow: hidden;border-right:1px solid #ceccbf; }.topNode{width: 100%;height: 198px;border-bottom: 1px solid #787463;background: url(music/pic/fmt01.jpg) center center;background-size:cover; transition:.7s;position: relative;}.lineNode{width: 100%;height: 46px;border-top: 1px solid #f9f7ee;border-bottom: 1px solid #a29d8a;background: url(musicimage/linebg.jpg) repeat-x;}.progressNode{width: 440px;height: 18px;float: left;margin:13px 0 0 28px;background: url(musicimage/progressbg.jpg) repeat-x;position: relative; }.progressNode .progressleft{width: 7px;height: 100%;position: absolute;left: 0;background: url(musicimage/leftNode.jpg);}.progressNode .progressright{width: 7px;height: 100%;position: absolute;right: 0;background: url(musicimage/rightNode.jpg);}.bottomNode{width: 100%;height: 157px;border-top: 1px solid #a29d8a;background: url(musicimage/bottombg.jpg) repeat-x;position: relative;}.lastNode{width: 75px;height: 74px;position: absolute;background: url(musicimage/lastBg.png) no-repeat;left: 118px;top: 39px;cursor: pointer;}.playNode{width: 95px;height: 94px;position: absolute;background: url(musicimage/playNode.png) no-repeat;left: 202px;top: 29px;cursor: pointer;}.nextNode{width: 75px;height: 74px;background: url(musicimage/rightbg.png) no-repeat;position: absolute;left: 306px;top: 39px;cursor: pointer;}.volumeNode{width: 37px;height: 32px;background: url(musicimage/volume.png) no-repeat; position: absolute;right: 43px;top: 58px;cursor: pointer;}.no_volumeNode{width: 37px;height: 32px;background: url(musicimage/no_volume.png) no-repeat; position: absolute;right: 43px;top: 58px;cursor: pointer;}.trueLine{position: absolute;left: 3px;top: 2px;height: 12px;width: 0%;background: url(musicimage/green_bg.png) repeat-x;border-radius: 6px;border-right: 1px solid #787463;}.musicName{color: white;position: absolute;bottom: 2px;left: 5px;} </style></head><body><!-- outerNode 最外层的元素 --><div class='outerNode'><!-- innerNode 内层元素 --><div class='innerNode'><!-- topNode 封⾯图元素 --><div class='topNode'><!-- ⾳乐名称 --><div class='musicName'></div></div><!-- lineNode 进度条元素 --><div class='lineNode'><!-- 进度条--><div class='progressNode'><div class='progressleft'></div><div class='progressright'></div><!-- 真正的进度条 --><div class='trueLine'></div>&l t ; / d i v &g t ;&l t ; / d i v &g t ; &。
mp3文件播放器源代码头文件代码(resource。
H)//{{NO_DEPENDENCIES}}// Microsoft Developer Studio generated include file.// Used by Script1.rc//#define IDI_ICON1 101#define IDI_MAINICON 101// Next default values for new objects//#ifdef APSTUDIO_INVOKED#ifndef APSTUDIO_READONL Y_SYMBOLS#define _APS_NEXT_RESOURCE_V ALUE 102#define _APS_NEXT_COMMAND_V ALUE 40001#define _APS_NEXT_CONTROL_V ALUE 1000#define _APS_NEXT_SYMED_V ALUE 101#endif#endif主程序代码(main)#include <windows.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <conio.h>#include <dshow.h>#pragma comment( lib, "Strmiids.lib")#pragma comment( lib, "winmm.lib" )#define V_RETURN(x) { hr = x; if( FAILED(hr) ) { return hr; } }////////////////////////////////////////////////////////////////////////////变量定义:IGraphBuilder* pGBuilder;IMediaPosition* pMPos;//////////////////////////////////////////////////////////////////////////HRESULT InitDirectShow(){HRESULT hr;CoInitialize(NULL); //初始化COM//创建各个对象CoCreateInstance(CLSID_FilterGraph, NULL,CLSCTX_INPROC, IID_IGraphBuilder, (void**)&pGBuilder);V_RETURN(pGBuilder->QueryInterface(IID_IMediaControl, (void**)&pMControl));V_RETURN(pGBuilder->QueryInterface(IID_IMediaPosition, (void**)&pMPos));return S_OK;}HRESULT LoadMusicFile(const char *path){HRESULT hr;CHAR strSoundPath[MAX_PATH]; //存储音乐所在路径WCHAR wstrSoundPath[MAX_PATH]; //存储UNICODE形式的路径strcpy(strSoundPath, path);MultiByteToWideChar(CP_ACP, 0, strSoundPath, -1,wstrSoundPath, MAX_PATH);V_RETURN(pGBuilder->RenderFile(wstrSoundPath, NULL)); //调入文件return S_OK;HRESULT Play(){HRESULT hr;//播放MP3的方法十分简单:return S_OK;}HRESULT Stop(){//最后,我们要停止播放音乐并释放各个对象:V_RETURN(pMControl->Stop()); //停止播放return S_OK;}void FreeDirectShow()//释放对象CoUninitialize(); //释放COM}//////////////////////////////////////////////////////////////////////////int main(){char cmd[255] = {NULL}, path[MAX_PATH] = {NULL};if(FAILED(InitDirectShow())){getch();return 1;}while(1){printf("*****这个是用于制作游戏的音乐播放程序,由于时间关系和便于学习我不printf("使用方法--输入以下命令:\n#载入并播放音乐:play\n#停止播放:scanf("%s", cmd);if(!stricmp(cmd, "play")){printf("请输入文件名:");printf("正在处理命令...\n", cmd, path);if(FAILED(LoadMusicFile(path))){getch();path[0] = 0;}else Play();else{printf("正在处理命令...\n", cmd, path);if(!stricmp(cmd, "replay")){Stop();}else if(!stricmp(cmd, "stop"))Stop();else if(!stricmp(cmd, "exit"))goto quit;else{printf("无法识别的命令");getch();}}quit:FreeDirectShow();}。
MusicInfoController.javapackage com.yarin.android.MusicPlayer;import android.content.ContentResolver;import android.database.Cursor;import .Uri;import android.provider.MediaStore;public class MusicInfoController{private static MusicInfoController mInstance = null;private MusicPlayerApp pApp = null;public static MusicInfoController getInstance(MusicPlayerApp app){if (mInstance == null){mInstance = new MusicInfoController(app);}return mInstance;}private MusicInfoController(MusicPlayerApp app){pApp = app;}public MusicPlayerApp getMusicPlayer(){return pApp;}private Cursor query(Uri uri, String[] prjs, String selections, String[] selectArgs, String order){ ContentResolver resolver = pApp.getContentResolver();if (resolver == null){return null;}return resolver.query(uri, prjs, selections, selectArgs, order);}public Cursor getAllSongs(){return query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);MusicList.javapackage com.yarin.android.MusicPlayer;import android.app.ListActivity;import android.content.BroadcastReceiver;import ponentName;import android.content.Context;import android.content.Intent;import android.content.IntentFilter;import android.content.ServiceConnection;import android.database.Cursor;import android.os.Bundle;import android.os.IBinder;import android.provider.MediaStore;import android.view.View;import android.widget.Button;import android.widget.ListAdapter;import android.widget.ListView;import android.widget.SimpleCursorAdapter;import android.widget.T extView;public class MusicList extends ListActivity{private MusicPlayerService mMusicPlayerService = null;private MusicInfoController mMusicInfoController = null;private Cursor mCursor = null;private TextView mTextView = null;private Button mPlayPauseButton = null;private Button mStopButton = null;private ServiceConnection mPlaybackConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { mMusicPlayerService = ((MusicPlayerService.LocalBinder)service).getService();}public void onServiceDisconnected(ComponentName className){ mMusicPlayerService = null;}};protected BroadcastReceiver mPlayerEvtReceiver = new BroadcastReceiver() { @Overridepublic void onReceive(Context context, Intent intent) {String action = intent.getAction();if (action.equals(MusicPlayerService.PLAYER_PREPARE_END)) {// will begin to playmTextView.setVisibility(View.INVISIBLE); mPlayPauseButton.setVisibility(View.VISIBLE);mStopButton.setVisibility(View.VISIBLE);mPlayPauseButton.setText(R.string.pause);} else if(action.equals(MusicPlayerService.PLAY_COMPLETED)){ mPlayPauseButton.setText(R.string.play);}}};public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(yout.list_layout);MusicPlayerApp musicPlayerApp=(MusicPlayerApp)getApplication(); mMusicInfoController =(musicPlayerApp).getMusicInfoController();// bind playback servicestartService(new Intent(this,MusicPlayerService.class));bindService(new Intent(this,MusicPlayerService.class), mPlaybackConnection,Context.BIND_AUTO_CREATE);mTextView = (TextView)findViewById(R.id.show_text); mPlayPauseButton = (Button)findViewById(R.id.play_pause_btn); mStopButton = (Button) findViewById(R.id.stop_btn);mPlayPauseButton.setOnClickListener(new Button.OnClickListener() {public void onClick(View v) {// Perform action on clickif (mMusicPlayerService != null && mMusicPlayerService.isPlaying()) { mMusicPlayerService.pause();mPlayPauseButton.setText(R.string.play);} else if (mMusicPlayerService != null){mMusicPlayerService.start();mPlayPauseButton.setText(R.string.pause);}}});mStopButton.setOnClickListener(new Button.OnClickListener() {public void onClick(View v) {// Perform action on clickif (mMusicPlayerService != null ) {mTextView.setVisibility(View.VISIBLE);mPlayPauseButton.setVisibility(View.INVISIBLE);mStopButton.setVisibility(View.INVISIBLE); mMusicPlayerService.stop();}}});IntentFilter filter = new IntentFilter();filter.addAction(MusicPlayerService.PLAYER_PREPARE_END);filter.addAction(MusicPlayerService.PLAY_COMPLETED);registerReceiver(mPlayerEvtReceiver, filter);}protected void onResume() {super.onResume();mCursor = mMusicInfoController.getAllSongs();ListAdapter adapter = new MusicListAdapter(this,yout.simple_expandable_list_item_2, mCursor, new String[]{}, new int[]{});setListAdapter(adapter);}protected void onListItemClick(ListView l, View v, int position, long id) {super.onListItemClick(l, v, position, id);if (mCursor == null ||mCursor.getCount() == 0) {return;}mCursor.moveToPosition(position);String url = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));mMusicPlayerService.setDataSource(url);mMusicPlayerService.start();}/********************************************************************/class MusicListAdapter extends SimpleCursorAdapter {public MusicListAdapter(Context context, int layout, Cursor c,String[] from, int[] to) { super(context, layout, c, from, to);}public void bindView(View view, Context context, Cursor cursor) {super.bindView(view, context, cursor);TextView titleView = (TextView) view.findViewById(android.R.id.text1);TextView artistView = (TextView) view.findViewById(android.R.id.text2);titleView.setText(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE)));artistView.setText(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST)));//int duration cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION));}public static String makeTimeString(long milliSecs) {StringBuffer sb = new StringBuffer();long m = milliSecs / (60 * 1000);sb.append(m < 10 ? "0" + m : m);sb.append(":");long s = (milliSecs % (60 * 1000)) / 1000;sb.append(s < 10 ? "0" + s : s);return sb.toString();}MusicPlayerApp.java package com.yarin.android.MusicPlayer;import android.app.Application;public class MusicPlayerApp extends Application{private MusicInfoController mMusicInfoController = null;public void onCreate(){ super.onCreate();mMusicInfoController = MusicInfoController.getInstance(this); }public MusicInfoController getMusicInfoController(){return mMusicInfoController;}}MusicPlayerService.javapackage com.yarin.android.MusicPlayer;import java.io.IOException;import android.app.Service;import android.content.Intent;import android.media.MediaPlayer;import android.os.Binder;import android.os.IBinder;public class MusicPlayerService extends Service{private final IBinder mBinder = new LocalBinder();private MediaPlayer mMediaPlayer = null;public static final String PLAYER_PREPARE_END = "com.yarin.musicplayerservice.prepared";public static final String PLAY_COMPLETED = "com.yarin.musicplayerservice.playcompleted";MediaPlayer.OnCompletionListener mCompleteListener = new MediaPlayer.OnCompletionListener(){public void onCompletion(MediaPlayer mp){ broadcastEvent(PLAY_COMPLETED);}};MediaPlayer.OnPreparedListener mPrepareListener = new MediaPlayer.OnPreparedListener(){public void onPrepared(MediaPlayer mp){ broadcastEvent(PLAYER_PREPARE_END);}};private void broadcastEvent(String what){Intent i = new Intent(what); sendBroadcast(i);}public void onCreate(){super.onCreate();mMediaPlayer = new MediaPlayer(); mMediaPlayer.setOnPreparedListener(mPrepareListener);mMediaPlayer.setOnCompletionListener(mCompleteListener);}public class LocalBinder extends Binder{public MusicPlayerService getService(){return MusicPlayerService.this;public IBinder onBind(Intent intent){return mBinder;}public void setDataSource(String path){try{mMediaPlayer.reset();mMediaPlayer.setDataSource(path); mMediaPlayer.prepare();}catch (IOException e){return;}catch (IllegalArgumentException e){return;}}public void start(){mMediaPlayer.start();}public void stop(){mMediaPlayer.stop();}public void pause(){mMediaPlayer.pause();public boolean isPlaying(){return mMediaPlayer.isPlaying();}public int getDuration(){return mMediaPlayer.getDuration();}public int getPosition(){return mMediaPlayer.getCurrentPosition();}public long seek(long whereto){mMediaPlayer.seekTo((int) whereto);return whereto;}}。
【转载】《MP3播放器生成器》参数解读制作MP3播放器,可使用《MP3播放器生成器》,为进一步了解熟悉该《生成器》,本文在参考《多行滚动歌词MP3播放器》的基础上,对该《生成器》涉及到的参数进行解读,为修改生成的代码或直接用手工制作提供方便。
一、播放器代码<EMBED src=播放器地址 width=宽度 height=高度 type=application/x-shockwave-flash QUALITY='high' flashvars="参数列表" WMODE="transparent"></EMBED>其中:1、播放器地址:src=/bfq/mp3bfqscq-wyfj.swf2、播放器尺寸:width=宽度 height=高度默认870*530。
按图片大小确定,最大1024*768。
纯视频背景,按默认的确定。
3、参数列表:flashvars="参数列表"。
二、参数说明1、歌曲(1)直接编写参数&mp3=MP3网址,mp3=MP3网址1|MP3网址2|......|MP3网址n。
多首歌曲时MP3网址之间用竖线字符分隔。
&mp3b=MP3备份网址,mp3b=MP3备份网址1|MP3备份网址2|......|MP3备份网址n。
多首歌曲时MP3备份网址之间用竖线字符分隔。
并与“MP3网址”一一对应。
&mp3n=歌曲名称,mp3n=歌曲名称1|歌曲名称2|......|歌曲名称n。
多首歌曲时名称之间用竖线字符分隔,并与“MP3网址”一一对应。
&lrc= LRC歌词,lrc=LRC歌词1|......|LRC歌词n。
多首歌曲时LRC歌词之间用英文竖线字符分隔。
并且与MP3网址一一对应。
(2)使用歌曲文件&mp3=歌曲文本文件网址。
如,/s/LtbWk2.gif/bfq/lb/liuzilin.gif/bfq/lb/denglijun.gif2、歌词&gcfs=歌词显示方式。
封装的类:using System;using System.Collections.Generic;using System.Text;using System.Runtime.InteropServices;namespace Musicar{class API{public const int WM_SYSCOMMAND = 0x112;public const int SC_MOVE = 0xF010;public const int HTCAPTION = 0x2;[DllImportAttribute("user32.dll")]public static extern int SendMessage(IntPtr hWnd,int Msg,int wParam,int lParam);[DllImportAttribute("user32.dll")]public static extern bool ReleaseCapture();[DllImport("kernel32.dll", CharSet = CharSet.Auto)]public static extern int GetShortPathName(string lpszLongPath,string shortFile,int cchBuffer);/// <summary>/// mciSendString:用来播放多媒体文件的API指令/// 类型包括:MPEG、A VI、WA V、MP3等等/// </summary>/// <param name="lpstrCommand">要发送的命令字符串,结构:[命令][设备别名][命令参数]</param>/// <param name="lpstrReturnString">返回信息缓冲区:指定大小的字符串变量</param>/// <param name="uReturnLength">缓冲区大小:字符串变量的长度</param>/// <param name="hwndCallback">回调方式,一般设为零</param>/// <returns>函数执行成功返回零,否则返回错误代码</returns>[DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]public static extern int mciSendString(string lpstrCommand,string lpstrReturnString,int uReturnLength,int hwndCallback);}}===================分割线============================================================using System;using System.Collections.Generic;using System.Text;namespace Musicar{class MusicPro{/// <summary>/// 打开并播放音频文件/// </summary>/// <param name="strFileName">音频文件全名</param>/// <param name="flagRepeat">是否重复播放</param>public static void OpenAndPlay(string strFileName, bool flagRepeat){string strCommand = "";string buf = "";strCommand = "open \"" + strFileName + "\" alias music";buf = buf.PadLeft(128, ' ');API.mciSendString(strCommand, buf, buf.Length, 0);//打开音频文件if (flagRepeat){strCommand = "play music repeat";}else{strCommand = "play music";}API.mciSendString(strCommand, buf, buf.Length, 0);//播放音频文件}/// <summary>/// 播放音频文件/// </summary>/// <param name="flagRepeat">是否重复播放</param>public static void Play(bool flagRepeat){string strCommand = "";if (flagRepeat){strCommand = "play music repeat";}else{strCommand = "play music";}API.mciSendString(strCommand, "", 0, 0);//播放音频文件}/// <summary>/// 停止播放/// </summary>public static void Stop(){API.mciSendString("stop music", "", 0, 0);}/// <summary>/// 关闭音频文件/// </summary>public static void Close(){API.mciSendString("close music", "", 0, 0);}/// <summary>/// 暂停播放/// </summary>public static void Pause(){API.mciSendString("pause music", "", 0, 0);}/// <summary>/// 继续播放/// </summary>public static void Resume(){API.mciSendString("resume music", "", 0, 0);}/// <summary>/// 前进到下一个位置/// </summary>public static void Forward(){API.mciSendString("step music", "", 0, 0);}/// <summary>/// 前进到下一个位置/// </summary>public static void Backward(){API.mciSendString("step music reverse", "", 0, 0);}/// <summary>/// 前进或后退N个步阶/// </summary>/// <param name="n">调整频数:正数向前,负数后退</param> public static void StepN(int nStep){API.mciSendString("step music by " + nStep.ToString(), "", 0, 0); }/// <summary>/// 获取当前播放位置/// </summary>/// <returns>当前播放位置:单位-秒</returns>public static int GetCurrentPosition(){string buf = "";buf = buf.PadLeft(128, ' ');API.mciSendString("status music position", buf, buf.Length, 0);buf = buf.Trim().Replace("\0", "");if (string.IsNullOrEmpty(buf)){return 0;}else{return (int)(Convert.ToDouble(buf)) / 1000;}}/// <summary>/// 获取播放文件的总长度/// </summary>/// <returns>播放文件长度:单位-秒</returns>public static int GetLenth(){string strLen = "";strLen = strLen.PadLeft(128, ' ');API.mciSendString("status music length", strLen, strLen.Length, 0);strLen = strLen.Trim().Replace("\0", "");if (string.IsNullOrEmpty(strLen)){return 0;}else{return Convert.ToInt32(strLen) / 1000;}}/// <summary>/// 获取当前播放状态信息/// </summary>/// <returns>播放状态,如播放完毕</returns>public static string GetStatus(){string strStatus = "";strStatus=strStatus.PadLeft(128, ' ');API.mciSendString("status music mode",strStatus,strStatus.Length, 0);return strStatus.Replace("\0", "");}/// <summary>/// 设置音量大小/// </summary>/// <param name="V alume">音量大小</param>/// <returns>设置成功,返回True,否则返回False</returns>public static bool SetV olume(int V alume){bool success = false;string strCommand = string.Format("setaudio music volume to {0}", V alume);if (API.mciSendString(strCommand, "", 0, 0) == 0){success = true;return success;}/// <summary>/// 获取当前音量大小/// </summary>/// <returns>当前音量大小</returns>public static int GetV olume(){string strV olume = "";strV olume = strV olume.PadLeft(128, ' ');API.mciSendString("status music volume", strV olume, strV olume.Length, 0);int nV olume = 0;strV olume = strV olume.Trim().Replace("\0", "");if (string.IsNullOrEmpty(strV olume)){nV olume = 0;}else{nV olume = Convert.ToInt32(strV olume);}return nV olume;}/// <summary>/// 设置指定播放位置/// </summary>/// <param name="process"></param>/// <returns></returns>public static bool SetProcess(int nPosition){bool success = false;string strCommand = string.Format("seek music to {0}", nPosition);if (API.mciSendString(strCommand, "", 0, 0) == 0){success = true;}return success;}}}前面介绍了一个使用MCI控件的CD播放器程序,实际上你可以用API函数写一个CD 播放器来代替使用多媒体控件。
MP3播放器源代码#Region#AutoIt3Wrapper_icon=HoneyTao.ico#AutoIt3Wrapper_Compression=4#AutoIt3Wrapper_Res_Description=WinXP & Win7#AutoIt3Wrapper_Res_LegalCopyright=K丶Q 製作。
#AutoIt3Wrapper_Res_Field=产品版本|1.0.0.0#AutoIt3Wrapper_Res_Field=产品名称|PeachPlayer#AutoIt3Wrapper_Res_Field=公司|K丶Q#AutoIt3Wrapper_Res_Field=内部名称|cALl Me KQ。
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0#AutoIt3Wrapper_Res_Field=源文件名|PeachPlayer.exe#EndRegion#include <ButtonConstants.au3>#include <ComboConstants.au3>#Include <GuiComboBoxEx.au3>#include <GUIConstantsEx.au3>#include <ProgressConstants.au3>#include <StaticConstants.au3>#include <WindowsConstants.au3>#include "Bass.au3"#include "GUIEnhance.au3"Local $ProcessList = ProcessList(@ScriptName)If $ProcessList[0][0] > 1 ThenMsgBox(0+16,"错误","请勿多次运行本程序")ExitEndIfGlobal $Happy1 = @TempDir & "\Happy1.jpg",$Happy2 = @TempDir & "\Happy2.jpg",$Peach1 = @TempDir & "\Peach1.jpg",$Peach2 = @TempDir & "\Peach2.jpg",$BassDll = @ScriptDir & "\bass.dll",$Icon = @TempDir & "\HoneyTao.dll",$SkinDll = @ScriptDir & "\SkinCrafterDll.dll",$Skin = @ScriptDir & "\Style.skf",$Dll,$MusicHandle,$PicFileInstall("Happy1.jpg",$Happy1,1)FileInstall("Happy2.jpg",$Happy2,1)FileInstall("Peach1.jpg",$Peach1,1)FileInstall("Peach2.jpg",$Peach2,1)FileInstall("HoneyTao.dll",$Icon,1)_BASS_Startup("bass.dll")_BASS_Init(0, -1, 44100, 0, "")If @error Then Exit$Gui = GUICreate("", 500, 395, -1, -1)_SkinGUI($SkinDll,$Skin,$Gui)$Pic = GUICtrlCreatePic("", 0, 0, 500, 331)If @MON & @MDAY = "1201" ThenGUICtrlSetImage($Pic,$Happy1)ElseGUICtrlSetImage($Pic,$Peach1)EndIf$Combo = GUICtrlCreateCombo("", 10, 340, 276, 25)_GUICtrlComboBox_SetDroppedWidth($Combo, 495)File(@ScriptDir)$Progress = GUICtrlCreateProgress(10, 366, 276, 20)$Stop = GUICtrlCreateIcon($Icon, 2, 295, 340, 48, 48)GUICtrlSetTip(-1,"停止")GUICtrlSetCursor (-1, 0)$First = GUICtrlCreateIcon($Icon, 3, 345, 340, 48, 48)GUICtrlSetTip(-1,"上一张图片")GUICtrlSetCursor (-1, 0)$Play = GUICtrlCreateIcon($Icon, 1, 395, 340, 48, 48)GUICtrlSetTip(-1,"播放")GUICtrlSetCursor (-1, 0)$Second = GUICtrlCreateIcon($Icon, 4, 445, 340, 48, 48)GUICtrlSetTip(-1,"下一张图片")GUICtrlSetCursor (-1, 0)_GUIEnhanceAnimateWin($Gui,1000,$GUI_EN_ANI_FADEIN)GUISetState(@SW_SHOW)If @MON & @MDAY = "1201" Then_GUIEnhanceAnimateTitle($Gui,"桃桃,祝妳生日快乐",$GUI_EN_TITLE_DROP) Else_GUIEnhanceAnimateTitle($Gui,"PeachPlayer",$GUI_EN_TITLE_DROP)EndIfWhile 1$Msg = GUIGetMsg()Switch $MsgCase $GUI_EVENT_CLOSEQuit()Case $ComboPlayMusic()Case $StopStopMusic()Case $FirstIf @MON & @MDAY = "1201" ThenGUICtrlSetImage($Pic,$Happy2)ElseGUICtrlSetImage($Pic,$Peach2)EndIfCase $PlayPlayMusic()Case $SecondIf @MON & @MDAY = "1201" ThenGUICtrlSetImage($Pic,$Happy1)ElseGUICtrlSetImage($Pic,$Peach1)EndIfEndSwitchWEndFunc _SkinGUI($SkincrafterDll, $SkincrafterSkin, $Handle)$Dll = DllOpen($SkincrafterDll)DllCall($Dll, "int:cdecl", "InitLicenKeys", "wstr", "SKINCRAFTER", "wstr", "", "wstr", "support@", "wstr", "DEMOSKINCRAFTERLICENCE")DllCall($Dll, "int:cdecl", "InitDecoration", "int", 1)DllCall($Dll, "int:cdecl", "LoadSkinFromFile", "wstr", $SkincrafterSkin)DllCall($Dll, "int:cdecl", "DecorateAs", "int", $Handle, "int", 25)DllCall($Dll, "int:cdecl", "ApplySkin")EndFuncFunc File($SearchDir)$FFArchiveFile = FileFindFirstFile($SearchDir & "\*.*")If $FFArchiveFile = -1 Then Return -1While 1$FNArchiveFile = FileFindNextFile($FFArchiveFile)If @error = 1 ThenFileClose($FFArchiveFile)Return 0ElseIf $FNArchiveFile = "." Or $FNArchiveFile = ".." ThenContinueLoopElseIf StringInStr(FileGetAttrib($SearchDir & "\" & $FNArchiveFile),"D") ThenFile($SearchDir & "\" & $FNArchiveFile)EndIfIf StringRight($FNArchiveFile,4) = ".mp3" ThenIf $FNArchiveFile = "Happy Birthday To You.mp3" ThenGUICtrlSetData($Combo,$SearchDir & "\" & $FNArchiveFile,$SearchDir & "\" & $FNArchiveFile)ElseGUICtrlSetData($Combo,$SearchDir & "\" & $FNArchiveFile)EndIfEndIfWEndEndFunc ;==>FileFunc ProgressStatus()Local $Pos = _BASS_ChannelGetPosition($MusicHandle,$BASS_POS_BYTE),$Length =_BASS_ChannelGetLength($MusicHandle,$BASS_POS_BYTE)If ($Pos >= $Length And $Length > 0) Or _BASS_ChannelIsActive($MusicHandle) = 0 Then_BASS_ChannelStop($MusicHandle)GUICtrlSetData($Progress,0)GUICtrlSetImage($Play,$Icon,1)GUICtrlSetTip($Play,"播放")AdlibUnRegister("ProgressStatus")ElseGUICtrlSetData($Progress,Int($Pos / $Length * 100))EndIfEndFunc ;==>ProgressStatusFunc PlayMusic()Local $MusicFile = GUICtrlRead($Combo)If _BASS_ChannelIsActive($MusicHandle) = 0 Then ;当没有播放时则播放音乐$MusicHandle = _BASS_StreamCreateFile(False,$MusicFile,0,0,0)_BASS_ChannelPlay($MusicHandle,1)GUICtrlSetImage($Play,$Icon,5)GUICtrlSetTip($Play,"暂停")ElseIf _BASS_ChannelIsActive($MusicHandle) = 1 Then ;当返回状态为1,即正在播放时$InFo = _BASS_ChannelGetInfo($MusicHandle)If $InFo[7] <> $MusicFile Then ;正在播放的音乐名与所选的文件不相同的话,即当前播放新文件If _BASS_ChannelStop($MusicHandle) Then$MusicHandle = _BASS_StreamCreateFile(False,$MusicFile,0,0,0)_BASS_ChannelPlay($MusicHandle,1)GUICtrlSetImage($Play,$Icon,5)GUICtrlSetTip($Play,"暂停")EndIfElse ;此时判断为暂停_BASS_ChannelPause($MusicHandle)GUICtrlSetImage($Play,$Icon,1)GUICtrlSetTip($Play,"播放")EndIfElseIf _BASS_ChannelIsActive($MusicHandle) = 3 Then ;当返回状态为3,即暂停播放时_BASS_ChannelPlay($MusicHandle,0)GUICtrlSetImage($Play,$Icon,5)GUICtrlSetTip($Play,"暂停")EndIfAdlibRegister("ProgressStatus", 100)ProgressStatus()EndFunc ;==>PlayMusicFunc StopMusic()_BASS_ChannelStop($MusicHandle)GUICtrlSetData($Progress,0)GUICtrlSetImage($Play,$Icon,1)GUICtrlSetTip($Play,"播放")EndFunc ;==>StopMusicFunc Quit()GUISetState(@SW_HIDE)_Bass_Free()If FileExists($Happy1) = 1 Then FileDelete($Happy1) If FileExists($Happy2) = 1 Then FileDelete($Happy2) If FileExists($Peach1) = 1 Then FileDelete($Peach1) If FileExists($Peach2) = 1 Then FileDelete($Peach2) If FileExists($Icon) = 1 Then FileDelete($Icon) DllCall($Dll, "int:cdecl", "DeInitDecoration") DllCall($Dll, "int:cdecl", "RemoveSkin")DllClose($Dll)ExitEndFunc ;==>Qui。
#include <sd.h>#include <ctype.h>/*SD卡MP3播放器源代码*/sbit XDCS =P2^2;sbit DREQ =P3^5;sbit XRESET=P3^4;sbit XCS =P2^5;sbit CLK =P3^3;sbit DATA =P2^3;#define VOL_V ALUE 0x0000/*分区记录结构*/struct PartRecord{unsigned char Active; //0x80表示此分区有效unsigned char StartHead; //分区的开始头unsigned char StartCylSect[2];//开始柱面与扇区unsigned char PartType; //分区类型unsigned char EndHead; //分区的结束头unsigned char EndCylSect[2]; //结束柱面与扇区unsigned char StartLBA[4]; //分区的第一个扇区unsigned char Size[4]; //分区的大小};/*分区扇区(绝对0扇区)定义如下*/struct PartSector{unsigned char PartCode[446]; //MBR的引导程序struct PartRecord Part[4]; //4个分区记录unsigned char BootSectSig0;unsigned char BootSectSig1;};struct FAT32_FAT_Item{unsigned char Item[4];};struct FAT32_FAT{struct FAT32_FAT_Item Items[128];};/*FAT32中对BPB的定义如下一共占用90个字节*/struct FAT32_BPB{unsigned char BS_jmpBoot[3]; //跳转指令offset: 0 unsigned char BS_OEMName[8]; // offset: 3 unsigned char BPB_BytesPerSec[2];//每扇区字节数offset:11 unsigned char BPB_SecPerClus[1]; //每簇扇区数offset:13 unsigned char BPB_RsvdSecCnt[2]; //保留扇区数目offset:14 unsigned char BPB_NumFATs[1]; //此卷中FAT表数offset:16 unsigned char BPB_RootEntCnt[2]; //FAT32为0 offset:17 unsigned char BPB_TotSec16[2]; //FAT32为0 offset:19 unsigned char BPB_Media[1]; //存储介质offset:21 unsigned char BPB_FATSz16[2]; //FAT32为0 offset:22 unsigned char BPB_SecPerTrk[2]; //磁道扇区数offset:24 unsigned char BPB_NumHeads[2]; //磁头数offset:26 unsigned char BPB_HiddSec[4]; //FAT区前隐扇区数offset:28 unsigned char BPB_TotSec32[4]; //该卷总扇区数offset:32unsigned char BPB_FATSz32[4]; //一个FAT表扇区数offset:36 unsigned char BPB_ExtFlags[2]; //FAT32特有offset:40 unsigned char BPB_FSVer[2]; //FAT32特有offset:42 unsigned char BPB_RootClus[4]; //根目录簇号offset:44 unsigned char FSInfo[2]; //保留扇区FSINFO扇区数offset:48 unsigned char BPB_BkBootSec[2]; //通常为6 offset:50 unsigned char BPB_Reserved[12]; //扩展用offset:52 unsigned char BS_DrvNum[1]; // offset:64 unsigned char BS_Reserved1[1]; // offset:65 unsigned char BS_BootSig[1]; // offset:66 unsigned char BS_V olID[4]; // offset:67 unsigned char BS_FilSysType[11]; // offset:71 unsigned char BS_FilSysType1[8]; //"FAT32 " offset:82 };// Structure of a dos directory entry. 一个dos目录结构的入口struct direntry{unsigned char deName[8]; // filename, blank filled (文件名)unsigned char deExtension[3]; // extension, blank filled (扩展)unsigned char deAttributes; // file attributes (文件属性)unsigned char deLowerCase; // NT VFAT lower case flags (set to zero)(系统保留)unsigned char deCHundredth; // hundredth of seconds in CTime (创建时间的10毫秒位)unsigned char deCTime[2]; // create time (文件创建时间)unsigned char deCDate[2]; // create date (文件创建日期)unsigned char deADate[2]; // access date (文件最后访问日期)unsigned char deHighClust[2]; // high unsigned chars of cluster number(文件起始簇号的高16位)unsigned char deMTime[2]; // last update time(文件的最近修改的时间)unsigned char deMDate[2]; // last update date(文件的最近修改日期)unsigned char deLowCluster[2]; // starting cluster of file (文件起始簇号的低16位)unsigned char deFileSize[4]; // size of file in unsigned chars (表示文件的长度)};// Stuctures 结构struct FileInfoStruct{unsigned char FileName[12]; //文件名unsigned long FileStartCluster; //< file starting cluster for last file accessed(文件首簇号)unsigned long FileCurCluster; //文件当前簇号unsigned long FileNextCluster; //下一簇号unsigned long FileSize; //< file size for last file accessed(文件大小)unsigned char FileAttr; //< file attr(属性)for last file accessed(文件属性)unsigned short FileCreateTime; //< file creation time for last file accessed (文件建立时间)unsigned short FileCreateDate; //< file creation date for last file accessed (文件建立日期)unsigned short FileMTime; //文件修改时间unsigned short FileMDate; //文件修改日期unsigned long FileSector; //<file record place(文件当前扇区)unsigned long FileOffset; //<file record offset (文件偏移量)};/*FAT32初始化时初始参数装入如下结构体中*/struct FAT32_Init_Arg{unsigned char BPB_Sector_No; //BPB所在扇区号unsigned long Total_Size; //磁盘的总容量unsigned long FirstDirClust; //根目录的开始簇unsigned long FirstDataSector; //文件数据开始扇区号unsigned int BytesPerSector; //每个扇区的字节数unsigned int FATsectors; //FAT表所占扇区数unsigned int SectorsPerClust; //每簇的扇区数unsigned long FirstFATSector; //第一个FAT表所在扇区unsigned long FirstDirSector; //第一个目录所在扇区unsigned long RootDirSectors; //根目录所占扇区数unsigned long RootDirCount; //根目录下的目录与文件数};//#define FIND_BPB_UP_RANGE 2000 //BPB不一定在0扇区,对0~FINE_BPB_UP_RANGE扇区进行扫描unsigned char xdata FAT32_Buffer[512]; //扇区数据读写缓冲区struct FAT32_Init_Arg Init_Arg; //初始化参数结构体实体struct FileInfoStruct FileInfo; //文件信息结构体实体unsigned char * FAT32_ReadSector(unsigned long LBA,unsigned char *buf) //FAT32中读取扇区的函数{MMC_get_data_LBA(LBA,512,buf);return buf;}unsigned char FAT32_WriteSector(unsigned long LBA,unsigned char *buf)//FAT32中写扇区的函数{return MMC_write_sector(LBA,buf);}unsigned long lb2bb(unsigned char *dat,unsigned char len) //小端转为大端{unsigned long temp=0;unsigned long fact=1;unsigned char i=0;for(i=0;i<len;i++){temp+=dat[i]*fact;fact*=256;}return temp;}unsigned long FAT32_FindBPB() //寻找BPB所在的扇区号{MMC_Init(); //SD卡初始化FAT32_ReadSector(0,FAT32_Buffer);if(FAT32_Buffer[0]!=0xeb)return lb2bb(((((struct PartSector *)(FAT32_Buffer))->Part[0]).StartLBA),4);elsereturn 0;}unsigned long FAT32_Get_Total_Size() //存储器的总容量,单位为M{MMC_Init(); //SD卡初始化FAT32_ReadSector(Init_Arg.BPB_Sector_No,FAT32_Buffer);return ((float)(lb2bb((((struct FAT32_BPB *)(FAT32_Buffer))->BPB_TotSec32),4)))*0.0004883; }void FAT32_Init(struct FAT32_Init_Arg *arg){struct FAT32_BPB *bpb;bpb=(struct FAT32_BPB *)(FAT32_Buffer); //将数据缓冲区指针转为struct FAT32_BPB 型指针arg->BPB_Sector_No =FAT32_FindBPB(); //FAT32_FindBPB()可以返回BPB所在的扇区号arg->Total_Size =FAT32_Get_Total_Size(); //FAT32_Get_Total_Size()可以返回磁盘的总容量,单位是兆arg->FATsectors =lb2bb((bpb->BPB_FATSz32) ,4); //装入FAT表占用的扇区数到FATsectors中arg->FirstDirClust =lb2bb((bpb->BPB_RootClus) ,4); //装入根目录簇号到FirstDirClust中arg->BytesPerSector =lb2bb((bpb->BPB_BytesPerSec),2); //装入每扇区字节数到BytesPerSector中arg->SectorsPerClust =lb2bb((bpb->BPB_SecPerClus) ,1); //装入每簇扇区数到SectorsPerClust 中arg->FirstFATSector =lb2bb((bpb->BPB_RsvdSecCnt) ,2)+arg->BPB_Sector_No;//装入第一个FAT表扇区号到FirstFATSector 中arg->RootDirCount =lb2bb((bpb->BPB_RootEntCnt) ,2); //装入根目录项数到RootDirCount中arg->RootDirSectors =(arg->RootDirCount)*32>>9; //装入根目录占用的扇区数到RootDirSectors中arg->FirstDirSector =(arg->FirstFATSector)+(bpb->BPB_NumFATs[0])*(arg->FATsectors); //装入第一个目录扇区到FirstDirSector中arg->FirstDataSector =(arg->FirstDirSector)+(arg->RootDirSectors); //装入第一个数据扇区到FirstDataSector中send_s("FATchushihuachengong"); //FAT初始化成功}void FAT32_EnterRootDir(){unsigned long iRootDirSector;unsigned long iDir;struct direntry *pDir;for(iRootDirSector=(Init_Arg.FirstDirSector);iRootDirSector<(Init_Arg.FirstDirSector)+(Init_Ar g.SectorsPerClust);iRootDirSector++){FAT32_ReadSector(iRootDirSector,FAT32_Buffer);for(iDir=0;iDir<Init_Arg.BytesPerSector;iDir+=sizeof(struct direntry)){pDir=((struct direntry *)(FAT32_Buffer+iDir));if((pDir->deName)[0]!=0x00 /*无效目录项*/ && (pDir->deName)[0]!=0xe5 /*无效目录项*/ && (pDir->deName)[0]!=0x0f /*无效属性*/){Printf_File_Name(pDir->deName);}}}}void FAT32_CopyName(unsigned char *Dname,unsigned char *filename){unsigned char i=0;for(;i<11;i++){Dname[i]=filename[i];}Dname[i]=0;}unsigned long FAT32_EnterDir(char *path){unsigned long iDirSector;unsigned long iCurSector=Init_Arg.FirstDirSector;unsigned long iDir;struct direntry *pDir;unsigned char DirName[12];unsigned char depth=0,i=0;while(path[i]!=0){if(path[i]=='\\'){depth++;}i++;}if(depth==1){return iCurSector; //如果是根目录,直接返回当前扇区号}for(iDirSector=iCurSector;iDirSector<(Init_Arg.FirstDirSector)+(Init_Arg.SectorsPerClust);iDirS ector++){FAT32_ReadSector(iDirSector,FAT32_Buffer);for(iDir=0;iDir<Init_Arg.BytesPerSector;iDir+=sizeof(struct direntry)){pDir=((struct direntry *)(FAT32_Buffer+iDir));if((pDir->deName)[0]!=0x00 /*无效目录项*/ && (pDir->deName)[0]!=0xe5 /*无效目录项*/ && (pDir->deName)[0]!=0x0f /*无效属性*/){Printf_File_Name(pDir->deName);}}}}unsigned char FAT32_CompareName(unsigned char *sname,unsigned char *dname){unsigned char i,j=8;unsigned char name_temp[12];for(i=0;i<11;i++) name_temp[i]=0x20;name_temp[11]=0;i=0;while(sname[i]!='.'){name_temp[i]=sname[i];i++;}i++;while(sname[i]!=0){name_temp[j++]=sname[i];i++;}//Printf(name_temp,0);for(i=0;i<11;i++){if(name_temp[i]!=dname[i]) return 0;}//Printf(name_temp,0);return 1;}unsigned long FAT32_GetNextCluster(unsigned long LastCluster) //给出一个簇号,计算出它的后继簇号的函数{unsigned long temp;struct FAT32_FAT *pFAT;struct FAT32_FAT_Item *pFAT_Item;temp=((LastCluster/128)+Init_Arg.FirstFATSector);//计算给定簇号对应的簇项的扇区号FAT32_ReadSector(temp,FAT32_Buffer);pFAT=(struct FAT32_FAT *)FAT32_Buffer;pFAT_Item=&((pFAT->Items)[LastCluster%128]);//在算出的扇区中提取簇项return lb2bb(pFAT_Item,4); //返回下一簇号}/*我们最终要实现的是对文件的读取,须要作到给定文件名后,可以得到相应文件的首簇。
using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.IO;namespace Ex182{public partial class Form1 : Form{private bool bool_no_sound = false;//是否静音private int num_sound_value = 0;//音量private string str_load_dir = "";//文件目录public Form1(){File.AppendAllText("LoadMusic.txt", "");//打开文件,追加字符串InitializeComponent();str_load_dir = File.ReadAllText("LoadMusic.txt");if (str_load_dir != "")Loadmusics();}private void Loadmusics(){try{ //遍历打开的文件,将文件名添加到ListBox控件中,加入播放文件列表foreach (string filename in Directory.GetFiles(str_load_dir)){FileInfo fi = new FileInfo(filename);if (fi.Extension == ".*"|| fi.Extension == ".wmv"|| fi.Extension == ".mp3"|| fi.Extension == ".wma" || fi.Extension == ".avi"){listBox1.Items.Add();axWindowsMediaPlayer1.currentPlaylist.insertItem(axWindowsMediaPlayer1.currentPlaylist.count, axWindowsMediaPlayer1.newMedia(filename));}}}catch{File.WriteAllText("LoadMusic.txt", "");}}private void打开ToolStripMenuItem_Click(object sender, EventArgs e){OpenFileDialog open = new OpenFileDialog();//对话框对象//过滤条件open.Filter = "所有文件.*|*.*|Wmv视频.wmv|*.wmv|歌曲.mp3|*.mp3|歌曲.wma|*.wma|文件.avi|*.avi";open.FilterIndex = 1;if (open.ShowDialog() == DialogResult.OK){FileInfo fi = new FileInfo(open.FileName);//获取文件int i;//将打开的文件添加到ListBox控件中for (i = 0; i < listBox1.Items.Count; i++){if ( == listBox1.Items[i].ToString())//有重复不添加break;}if (i == listBox1.Items.Count){this.listBox1.Items.Add();//添加到ListBox控件中//播放文件axWindowsMediaPlayer1.currentPlaylist.insertItem(axWindowsMediaPlayer1.currentPlaylist.count, axWindowsMediaPlayer1.newMedia(open.FileName));}}}bool isplayer = true;private void label3_Click(object sender, EventArgs e){if (isplayer){axWindowsMediaPlayer1.Ctlcontrols.pause(); //暂停bel3.Text = "播放";isplayer = false;}else{axWindowsMediaPlayer1.Ctlcontrols.play(); //播放bel3.Text = "暂停";isplayer = true;}}private void label4_Click(object sender, EventArgs e){axWindowsMediaPlayer1.Ctlcontrols.stop(); //停止}private void label1_Click(object sender, EventArgs e){int index=this.listBox1.SelectedIndex;if (index >= 1){this.axWindowsMediaPlayer1.Ctlcontrols.previous(); //上一首this.listBox1.SelectedIndex = this.listBox1.SelectedIndex - 1;}else{this.listBox1.SelectedIndex =0;}}private void label2_Click(object sender, EventArgs e){int index = listBox1.SelectedIndex;if (index < listBox1.Items.Count){this.axWindowsMediaPlayer1.Ctlcontrols.next(); //下一首this.listBox1.SelectedIndex = this.listBox1.SelectedIndex + 1;}}private void label5_Click(object sender, EventArgs e){axWindowsMediaPlayer1.fullScreen = true; //全屏}private void tbVolume_Scroll(object sender, EventArgs e){this.axWindowsMediaPlayer1.settings.volume = tbVolume.Value; //音量同步 }private void上一首ToolStripMenuItem_Click(object sender, EventArgs e){axWindowsMediaPlayer1.Ctlcontrols.stop(); //停止}private void快进ToolStripMenuItem_Click(object sender, EventArgs e){this.axWindowsMediaPlayer1.Ctlcontrols.fastForward(); //快进}private void快退ToolStripMenuItem_Click(object sender, EventArgs e){this.axWindowsMediaPlayer1.Ctlcontrols.fastReverse(); //快退}private void单曲循环ToolStripMenuItem_Click(object sender, EventArgs e){axWindowsMediaPlayer1.settings.setMode("loop", true); //循环播放 }private void随机播放ToolStripMenuItem_Click(object sender, EventArgs e){axWindowsMediaPlayer1.settings.setMode("shuffle", true); //随机播放 }private void顺序播放ToolStripMenuItem_Click(object sender, EventArgs e){axWindowsMediaPlayer1.settings.setMode("shuffle", false); //顺序播放 }private void lblVolume_Click(object sender, EventArgs e){if (bool_no_sound == false){num_sound_value = this.tbVolume.Value;bool_no_sound = true;this.lblVolume.Text = "音量";tbVolume.Value = 0;axWindowsMediaPlayer1.settings.volume = 0; //静音}else{bool_no_sound = false;tbVolume.Value = num_sound_value;axWindowsMediaPlayer1.settings.volume = num_sound_value;this.lblVolume.Text = "静音"; //非静音}}private void全屏ToolStripMenuItem_Click(object sender, EventArgs e){axWindowsMediaPlayer1.fullScreen = true; //全屏}private void原始比例ToolStripMenuItem_Click(object sender, EventArgs e){this.Width = 378;this.Height = 278;}private void listBox1_DoubleClick(object sender, EventArgs e){int j = listBox1.SelectedIndex;axWindowsMediaPlayer1.Ctlcontrols.playItem(axWindowsMediaPlayer1.currentPlaylist.get_Item(j)); }private void button1_Click(object sender, EventArgs e){OpenFileDialog open = new OpenFileDialog();//对话框对象//过滤条件open.Filter = "所有文件.*|*.*|Wmv视频.wmv|*.wmv|歌曲.mp3|*.mp3|歌曲.wma|*.wma|文件.avi|*.avi";open.FilterIndex = 1;if (open.ShowDialog() == DialogResult.OK){FileInfo fi = new FileInfo(open.FileName);//获取文件int i;//将打开的文件添加到ListBox控件中for (i = 0; i < listBox1.Items.Count; i++){if ( == listBox1.Items[i].ToString())//有重复不添加break;}if (i == listBox1.Items.Count){this.listBox1.Items.Add();//添加到ListBox控件中//播放文件axWindowsMediaPlayer1.currentPlaylist.insertItem(axWindowsMediaPlayer1.currentPlaylist.count, axWindowsMediaPlayer1.newMedia(open.FileName));}}}}}。
Public Class Form1Dim soundname As String()Dim i As IntegerDim j, l As BooleanDim k As IntegerDim filename As String'取歌曲的名字Dim path As String()Dim s, m As IntegerDim luj As StringDim count As Integer'用来声明选择歌曲的数目Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loadi = 0j = Falsel = FalseLabel2.Text = "歌曲名:"Label3.Text = "歌曲演唱者:"Label4.Text = "歌曲描述:"Label5.Text = "歌曲类型:"Label6.Text = "歌曲大小:"End SubPrivate Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Clickselectsound()End SubPrivate Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.ScrollMe.AxWindowsMediaPlayer1.settings.volume = TrackBar1.ValueEnd SubPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.ClickIf Timer1.Enabled = False ThenTimer1.Enabled = TrueElseTimer1.Enabled = FalseEnd IfIf i = 0 ThenMe.AxWindowsMediaPlayer1.Ctlcontrols.pause()i = 1Button3.Text = "继续"Exit SubEnd IfIf i = 1 ThenMe.AxWindowsMediaPlayer1.Ctlcontrols.play()Button3.Text = "暂停"i = 0Exit SubEnd IfEnd SubPrivate Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.TickDim string1, ss, sss As Stringstring1 =ListBox1.SelectedItem.ToString.Substring(stIndexOf("\") + 1)filename = string1.Substring(0, stIndexOf("."))luj = ListBox1.SelectedItem.ToString.Substring(0,stIndexOf(".")) + ".lrc"ss = Me.AxWindowsMediaPlayer1.Ctlcontrols.currentPositionStringbel1.Text = ssIf Dir(luj) <> Nothing ThenDim fr As System.IO.StreamReader = New System.IO.StreamReader(luj,System.Text.Encoding.Default)sss = fr.ReadLine '我们读取的第一行歌词While (sss <> "")If (stIndexOf(ss) <> -1) Then'时间匹配了歌词中的时间Me.TextBox1.Text = sss.Substring(stIndexOf("]") + 1)Form2.TextBox1.Text = Me.TextBox1.TextEnd Ifsss = fr.ReadLineEnd WhileElseTextBox1.Text = "Not Find! 请从网上下载歌词!"Form2.TextBox1.Text = "Not Find! 请从网上下载歌词!"End IfLabel1.Text = "当前进度:" + Me.AxWindowsMediaPlayer1.Ctlcontrols.currentPositionString End SubPrivate Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e AsSystem.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.ScrollMe.AxWindowsMediaPlayer1.Ctlcontrols.currentPosition = Me.HScrollBar1.Value / 1000 * Me.AxWindowsMediaPlayer1.currentMedia.durationEnd SubPrivate Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.ClickMe.AxWindowsMediaPlayer1.Ctlcontrols.fastForward()End SubPrivate Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles ListBox1.SelectedIndexChangedMe.AxWindowsMediaPlayer1.URL = ListBox1.Items(ListBox1.SelectedIndex)Me.AxWindowsMediaPlayer1.Ctlcontrols.play()Label2.Text = "歌曲名:" + Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Title")Label3.Text = "歌曲演唱者:"+ Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Author") Label4.Text = "歌曲描述:" +Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Description")Label5.Text = "歌曲类型:"+ Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("FileType") Label6.Text = "歌曲大小:"+ Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("FileSize") Timer1.Start()End SubPrivate Sub playsound()Timer1.Stop()TrackBar1.Value = Me.AxWindowsMediaPlayer1.settings.volumeIf j = False ThenMe.AxWindowsMediaPlayer1.URL = ListBox1.Items(ListBox1.SelectedIndex) ElseIf j = True Thenk = (ListBox1.SelectedIndex + 1) Mod soundname.LengthMe.AxWindowsMediaPlayer1.URL = ListBox1.Items(k)j = FalseEnd IfListBox1.SelectedIndex = kMe.AxWindowsMediaPlayer1.Ctlcontrols.play()Label2.Text = "歌曲名:" + Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Title")Label3.Text = "歌曲演唱者:"+ Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Author") Label4.Text = "歌曲描述:" +Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Description")Label5.Text = "歌曲类型:"+ Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("FileType") Label6.Text = "歌曲大小:"+ Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("FileSize") Timer1.Start()End SubPrivate Sub selectsound()Dim open As New OpenFileDialogDim i As IntegerWith open.Filter = "所有mp3文件(*.mp3)|*.mp3|所有wma文件(*.wma)|*.wma".Multiselect = True.Title = "请选择歌曲"End WithIf (open.ShowDialog = Windows.Forms.DialogResult.OK) Thensoundname = open.FileNamesFor i = 0 To soundname.GetUpperBound(0)ListBox1.Items.Add(soundname(i))NextListBox1.SelectedIndex = 0End IfEnd SubPrivate Sub AxWindowsMediaPlayer1_Enter(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles AxWindowsMediaPlayer1.EnterIf AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsMediaEnded Thenj = TrueTimer2.Start()End IfEnd SubPrivate Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tickplaysound()Timer2.Stop()End SubPrivate Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.ClickTimer1.Stop()If ListBox1.SelectedIndex = 0 ThenMe.AxWindowsMediaPlayer1.URL = ListBox1.Items(soundname.Length - 1)ListBox1.SelectedIndex = (soundname.Length - 1)ElseMe.AxWindowsMediaPlayer1.URL = ListBox1.Items((ListBox1.SelectedIndex Mod soundname.Length) - 1)ListBox1.SelectedIndex = (ListBox1.SelectedIndex Mod soundname.Length) - 1 End IfMe.AxWindowsMediaPlayer1.Ctlcontrols.play()Label2.Text = "歌曲名:" + Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Title")Label3.Text = "歌曲演唱者:"+ Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Author") Label4.Text = "歌曲描述:" +Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("Description")Label5.Text = "歌曲类型:"+ Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("FileType") Label6.Text = "歌曲大小:"+ Me.AxWindowsMediaPlayer1.currentMedia.getItemInfo("FileSize") Timer1.Start()End SubPrivate Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.ClickForm2.Show()End SubEnd Class。
音频播放器代码-代码大全播放器样式和代码1.简易播放器一(手动) 主要音频格式:rm,ra,ram,mp3简易播放器(自动播放)代码,提取方法:右击,全选,复制<center><embed src="音频绝对地址" width=200 height=30 controls=ControlPanel loop=true autostart=true volume=100 type=audio/x-pn-realaudio-plugin Initfn=load-types mime-types=mime.types></center>2.简易播放器二(手动) 主要格式wma,mp3简易播放器二(自动播放)代码.提取方法:右击,全选,复制<center><EMBED style="FILTER: xray(); WIDTH: 200px; HEIGHT: 30px" src="音频绝对地址" type=audio/x-mpegurl volume="0" loop="-1" autostart="true" allowscriptaccess="never"></EMBED></center>3.多功能播放器(手动)各类格式音视频 (rm等除外)多功能播放器(自动播放)代码,提取方法:右击,全选,复制(如果是视频文件,请将以下代码里的值改为height=350)<center><OBJECT id=phx height=45 width=350 classid=clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6><PARAM NAME="URL" VALUE="音视频绝对地址"><PARAM NAME="rate" VALUE="1"><PARAM NAME="balance" VALUE="0"><PARAM NAME="currentPosition" VALUE="0"><PARAM NAME="defaultFrame" VALUE=""><PARAM NAME="playCount" VALUE="1"><PARAM NAME="autoStart" VALUE="-1"><PARAM NAME="currentMarker" VALUE="0"><PARAM NAME="invokeURLs" VALUE="-1"><PARAM NAME="baseURL" VALUE=""><PARAM NAME="volume" VALUE="78"><PARAM NAME="mute" VALUE="0"><PARAM NAME="uiMode"VALUE="full"><PARAM NAME="stretchToFit" VALUE="0"><PARAM NAME="windowlessVideo" VALUE="0"><PARAM NAME="enabled" VALUE="-1"><PARAM NAME="enableContextMenu" VALUE="-1"><PARAM NAME="fullScreen" VALUE="0"><PARAM NAME="SAMIStyle" VALUE=""><PARAM NAME="SAMILang" VALUE=""><PARAM NAME="SAMIFilename" VALUE=""><PARAM NAME="captioningID" VALUE=""><PARAM NAME="enableErrorDialogs" VALUE="0"><PARAM NAME="_cx" VALUE="8811"><PARAM NAME="_cy" VALUE="1217"></OBJECT></CENTER>4.微软简易播放器(手动)音频格式:mp3,wma等微软播放器(自动播放)代码,提取方法:右击,全选,复制<P align=center><EMBED src="音频绝对地址" width=320 height=45 type=audio/mpeg autostart="0"></EMBED></P>5.标签型播放器(手动播放)音频格式 mp3,wma标签型播放器(自动播放)代码:代码提取方法:右击,全选,复制<DIV align=center><EMBED src="音频绝对地址" width=300 height=140 type=audio/x-ms-wma balance="true" showpositioncontrols="true" showtracker="true" showaudiocontrols="true" showcontrols="true" showstatusbar="true" showdisplay="true" displaysize="0" volume="100" autosize="false" autostart="true" animationatstart="false" transparentatstart="true"></div>注:1,以上显示的播放器均设置为手动播放,即:autostart="0".如需自动播放请设置autostart="true".2,以上各播放器代码里均设置为自动播放,即.autostart="true",如需手动播放请设置autostart="0"样式和代码1.简易播放器一(手动) 主要音频格式:rm,ra,ram,mp3简易播放器(自动播放)代码,提取方法:右击,全选,复制<center><embed src="音频绝对地址" width=200 height=30 controls=ControlPanel loop=true autostart=true volume=100 type=audio/x-pn-realaudio-plugin Initfn=load-types mime-types=mime.types></center>2.简易播放器二(手动) 主要格式wma,mp3简易播放器二(自动播放)代码.提取方法:右击,全选,复制<center><EMBED style="FILTER: xray(); WIDTH: 200px; HEIGHT: 30px" src="音频绝对地址" type=audio/x-mpegurl volume="0" loop="-1" autostart="true" allowscriptaccess="never"></EMBED></center>3.多功能播放器(手动)各类格式音视频 (rm等除外)多功能播放器(自动播放)代码,提取方法:右击,全选,复制(如果是视频文件,请将以下代码里的值改为height=350)<center><OBJECT id=phx height=45 width=350 classid=clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6><PARAM NAME="URL" VALUE="音视频绝对地址"><PARAM NAME="rate" VALUE="1"><PARAM NAME="balance" VALUE="0"><PARAM NAME="currentPosition" VALUE="0"><PARAM NAME="defaultFrame" VALUE=""><PARAM NAME="playCount" VALUE="1"><PARAM NAME="autoStart" VALUE="-1"><PARAM NAME="currentMarker" VALUE="0"><PARAM NAME="invokeURLs" VALUE="-1"><PARAM NAME="baseURL" VALUE=""><PARAM NAME="volume" VALUE="78"><PARAM NAME="mute" VALUE="0"><PARAM NAME="uiMode" VALUE="full"><PARAM NAME="stretchToFit" VALUE="0"><PARAM NAME="windowlessVideo"VALUE="0"><PARAM NAME="enabled" VALUE="-1"><PARAM NAME="enableContextMenu" VALUE="-1"><PARAM NAME="fullScreen" VALUE="0"><PARAM NAME="SAMIStyle" VALUE=""><PARAM NAME="SAMILang" VALUE=""><PARAM NAME="SAMIFilename" VALUE=""><PARAM NAME="captioningID" VALUE=""><PARAM NAME="enableErrorDialogs" VALUE="0"><PARAM NAME="_cx" VALUE="8811"><PARAM NAME="_cy" VALUE="1217"></OBJECT></CENTER>4.微软简易播放器(手动)音频格式:mp3,wma等微软播放器(自动播放)代码,提取方法:右击,全选,复制<P align=center><EMBED src="音频绝对地址" width=320 height=45 type=audio/mpeg autostart="0"></EMBED></P>5.标签型播放器(手动播放)音频格式 mp3,wma标签型播放器(自动播放)代码:代码提取方法:右击,全选,复制<DIV align=center><EMBED src="音频绝对地址" width=300 height=140 type=audio/x-ms-wma balance="true" showpositioncontrols="true" showtracker="true" showaudiocontrols="true" showcontrols="true" showstatusbar="true" showdisplay="true" displaysize="0" volume="100" autosize="false" autostart="true" animationatstart="false" transparentatstart="true"></div>注:1,以上显示的播放器均设置为手动播放,即:autostart="0".如需自动播放请设置autostart="true".2,以上各播放器代码里均设置为自动播放,即.autostart="true",如需手动播放请设置autostart="0"。
#include <sd.h>#include <ctype.h>/*SD卡MP3播放器源代码*/sbit XDCS =P2^2;sbit DREQ =P3^5;sbit XRESET=P3^4;sbit XCS =P2^5;sbit CLK =P3^3;sbit DATA =P2^3;#define VOL_V ALUE 0x0000/*分区记录结构*/struct PartRecord{unsigned char Active; //0x80表示此分区有效unsigned char StartHead; //分区的开始头unsigned char StartCylSect[2];//开始柱面与扇区unsigned char PartType; //分区类型unsigned char EndHead; //分区的结束头unsigned char EndCylSect[2]; //结束柱面与扇区unsigned char StartLBA[4]; //分区的第一个扇区unsigned char Size[4]; //分区的大小};/*分区扇区(绝对0扇区)定义如下*/struct PartSector{unsigned char PartCode[446]; //MBR的引导程序struct PartRecord Part[4]; //4个分区记录unsigned char BootSectSig0;unsigned char BootSectSig1;};struct FAT32_FAT_Item{unsigned char Item[4];};struct FAT32_FAT{struct FAT32_FAT_Item Items[128];};/*FAT32中对BPB的定义如下一共占用90个字节*/struct FAT32_BPB{unsigned char BS_jmpBoot[3]; //跳转指令offset: 0 unsigned char BS_OEMName[8]; // offset: 3 unsigned char BPB_BytesPerSec[2];//每扇区字节数offset:11 unsigned char BPB_SecPerClus[1]; //每簇扇区数offset:13 unsigned char BPB_RsvdSecCnt[2]; //保留扇区数目offset:14 unsigned char BPB_NumFATs[1]; //此卷中FAT表数offset:16 unsigned char BPB_RootEntCnt[2]; //FAT32为0 offset:17 unsigned char BPB_TotSec16[2]; //FAT32为0 offset:19 unsigned char BPB_Media[1]; //存储介质offset:21 unsigned char BPB_FATSz16[2]; //FAT32为0 offset:22 unsigned char BPB_SecPerTrk[2]; //磁道扇区数offset:24 unsigned char BPB_NumHeads[2]; //磁头数offset:26 unsigned char BPB_HiddSec[4]; //FAT区前隐扇区数offset:28 unsigned char BPB_TotSec32[4]; //该卷总扇区数offset:32unsigned char BPB_FATSz32[4]; //一个FAT表扇区数offset:36 unsigned char BPB_ExtFlags[2]; //FAT32特有offset:40 unsigned char BPB_FSVer[2]; //FAT32特有offset:42 unsigned char BPB_RootClus[4]; //根目录簇号offset:44 unsigned char FSInfo[2]; //保留扇区FSINFO扇区数offset:48 unsigned char BPB_BkBootSec[2]; //通常为6 offset:50 unsigned char BPB_Reserved[12]; //扩展用offset:52 unsigned char BS_DrvNum[1]; // offset:64 unsigned char BS_Reserved1[1]; // offset:65 unsigned char BS_BootSig[1]; // offset:66 unsigned char BS_V olID[4]; // offset:67 unsigned char BS_FilSysType[11]; // offset:71 unsigned char BS_FilSysType1[8]; //"FAT32 " offset:82 };// Structure of a dos directory entry. 一个dos目录结构的入口struct direntry{unsigned char deName[8]; // filename, blank filled (文件名)unsigned char deExtension[3]; // extension, blank filled (扩展)unsigned char deAttributes; // file attributes (文件属性)unsigned char deLowerCase; // NT VFAT lower case flags (set to zero)(系统保留)unsigned char deCHundredth; // hundredth of seconds in CTime (创建时间的10毫秒位)unsigned char deCTime[2]; // create time (文件创建时间)unsigned char deCDate[2]; // create date (文件创建日期)unsigned char deADate[2]; // access date (文件最后访问日期)unsigned char deHighClust[2]; // high unsigned chars of cluster number(文件起始簇号的高16位)unsigned char deMTime[2]; // last update time(文件的最近修改的时间)unsigned char deMDate[2]; // last update date(文件的最近修改日期)unsigned char deLowCluster[2]; // starting cluster of file (文件起始簇号的低16位)unsigned char deFileSize[4]; // size of file in unsigned chars (表示文件的长度)};// Stuctures 结构struct FileInfoStruct{unsigned char FileName[12]; //文件名unsigned long FileStartCluster; //< file starting cluster for last file accessed(文件首簇号)unsigned long FileCurCluster; //文件当前簇号unsigned long FileNextCluster; //下一簇号unsigned long FileSize; //< file size for last file accessed(文件大小)unsigned char FileAttr; //< file attr(属性)for last file accessed(文件属性)unsigned short FileCreateTime; //< file creation time for last file accessed (文件建立时间)unsigned short FileCreateDate; //< file creation date for last file accessed (文件建立日期)unsigned short FileMTime; //文件修改时间unsigned short FileMDate; //文件修改日期unsigned long FileSector; //<file record place(文件当前扇区)unsigned long FileOffset; //<file record offset (文件偏移量)};/*FAT32初始化时初始参数装入如下结构体中*/struct FAT32_Init_Arg{unsigned char BPB_Sector_No; //BPB所在扇区号unsigned long Total_Size; //磁盘的总容量unsigned long FirstDirClust; //根目录的开始簇unsigned long FirstDataSector; //文件数据开始扇区号unsigned int BytesPerSector; //每个扇区的字节数unsigned int FATsectors; //FAT表所占扇区数unsigned int SectorsPerClust; //每簇的扇区数unsigned long FirstFATSector; //第一个FAT表所在扇区unsigned long FirstDirSector; //第一个目录所在扇区unsigned long RootDirSectors; //根目录所占扇区数unsigned long RootDirCount; //根目录下的目录与文件数};//#define FIND_BPB_UP_RANGE 2000 //BPB不一定在0扇区,对0~FINE_BPB_UP_RANGE扇区进行扫描unsigned char xdata FAT32_Buffer[512]; //扇区数据读写缓冲区struct FAT32_Init_Arg Init_Arg; //初始化参数结构体实体struct FileInfoStruct FileInfo; //文件信息结构体实体unsigned char * FAT32_ReadSector(unsigned long LBA,unsigned char *buf) //FAT32中读取扇区的函数{MMC_get_data_LBA(LBA,512,buf);return buf;}unsigned char FAT32_WriteSector(unsigned long LBA,unsigned char *buf)//FAT32中写扇区的函数{return MMC_write_sector(LBA,buf);}unsigned long lb2bb(unsigned char *dat,unsigned char len) //小端转为大端{unsigned long temp=0;unsigned long fact=1;unsigned char i=0;for(i=0;i<len;i++){temp+=dat[i]*fact;fact*=256;}return temp;}unsigned long FAT32_FindBPB() //寻找BPB所在的扇区号{MMC_Init(); //SD卡初始化FAT32_ReadSector(0,FAT32_Buffer);if(FAT32_Buffer[0]!=0xeb)return lb2bb(((((struct PartSector *)(FAT32_Buffer))->Part[0]).StartLBA),4);elsereturn 0;}unsigned long FAT32_Get_Total_Size() //存储器的总容量,单位为M{MMC_Init(); //SD卡初始化FAT32_ReadSector(Init_Arg.BPB_Sector_No,FAT32_Buffer);return ((float)(lb2bb((((struct FAT32_BPB *)(FAT32_Buffer))->BPB_TotSec32),4)))*0.0004883; }void FAT32_Init(struct FAT32_Init_Arg *arg){struct FAT32_BPB *bpb;bpb=(struct FAT32_BPB *)(FAT32_Buffer); //将数据缓冲区指针转为struct FAT32_BPB 型指针arg->BPB_Sector_No =FAT32_FindBPB(); //FAT32_FindBPB()可以返回BPB所在的扇区号arg->Total_Size =FAT32_Get_Total_Size(); //FAT32_Get_Total_Size()可以返回磁盘的总容量,单位是兆arg->FATsectors =lb2bb((bpb->BPB_FATSz32) ,4); //装入FA T表占用的扇区数到FATsectors中arg->FirstDirClust =lb2bb((bpb->BPB_RootClus) ,4); //装入根目录簇号到FirstDirClust中arg->BytesPerSector =lb2bb((bpb->BPB_BytesPerSec),2); //装入每扇区字节数到BytesPerSector中arg->SectorsPerClust =lb2bb((bpb->BPB_SecPerClus) ,1); //装入每簇扇区数到SectorsPerClust 中arg->FirstFATSector =lb2bb((bpb->BPB_RsvdSecCnt) ,2)+arg->BPB_Sector_No;//装入第一个FAT表扇区号到FirstFATSector 中arg->RootDirCount =lb2bb((bpb->BPB_RootEntCnt) ,2); //装入根目录项数到RootDirCount中arg->RootDirSectors =(arg->RootDirCount)*32>>9; //装入根目录占用的扇区数到RootDirSectors中arg->FirstDirSector =(arg->FirstFATSector)+(bpb->BPB_NumFATs[0])*(arg->FATsectors); //装入第一个目录扇区到FirstDirSector中arg->FirstDataSector =(arg->FirstDirSector)+(arg->RootDirSectors); //装入第一个数据扇区到FirstDataSector中send_s("FATchushihuachengong"); //FAT初始化成功}void FAT32_EnterRootDir(){unsigned long iRootDirSector;unsigned long iDir;struct direntry *pDir;for(iRootDirSector=(Init_Arg.FirstDirSector);iRootDirSector<(Init_Arg.FirstDirSector)+(Init_Ar g.SectorsPerClust);iRootDirSector++){FAT32_ReadSector(iRootDirSector,FAT32_Buffer);for(iDir=0;iDir<Init_Arg.BytesPerSector;iDir+=sizeof(struct direntry)){pDir=((struct direntry *)(FAT32_Buffer+iDir));if((pDir->deName)[0]!=0x00 /*无效目录项*/ && (pDir->deName)[0]!=0xe5 /*无效目录项*/ && (pDir->deName)[0]!=0x0f /*无效属性*/){Printf_File_Name(pDir->deName);}}}}void FAT32_CopyName(unsigned char *Dname,unsigned char *filename){unsigned char i=0;for(;i<11;i++){Dname[i]=filename[i];}Dname[i]=0;}unsigned long FAT32_EnterDir(char *path){unsigned long iDirSector;unsigned long iCurSector=Init_Arg.FirstDirSector;unsigned long iDir;struct direntry *pDir;unsigned char DirName[12];unsigned char depth=0,i=0;while(path[i]!=0){if(path[i]=='\\'){depth++;}i++;}if(depth==1){return iCurSector; //如果是根目录,直接返回当前扇区号}for(iDirSector=iCurSector;iDirSector<(Init_Arg.FirstDirSector)+(Init_Arg.SectorsPerClust);iDirS ector++){FAT32_ReadSector(iDirSector,FAT32_Buffer);for(iDir=0;iDir<Init_Arg.BytesPerSector;iDir+=sizeof(struct direntry)){pDir=((struct direntry *)(FAT32_Buffer+iDir));if((pDir->deName)[0]!=0x00 /*无效目录项*/ && (pDir->deName)[0]!=0xe5 /*无效目录项*/ && (pDir->deName)[0]!=0x0f /*无效属性*/){Printf_File_Name(pDir->deName);}}}}unsigned char FAT32_CompareName(unsigned char *sname,unsigned char *dname){unsigned char i,j=8;unsigned char name_temp[12];for(i=0;i<11;i++) name_temp[i]=0x20;name_temp[11]=0;i=0;while(sname[i]!='.'){name_temp[i]=sname[i];i++;}i++;while(sname[i]!=0){name_temp[j++]=sname[i];i++;}//Printf(name_temp,0);for(i=0;i<11;i++){if(name_temp[i]!=dname[i]) return 0;}//Printf(name_temp,0);return 1;}unsigned long FAT32_GetNextCluster(unsigned long LastCluster) //给出一个簇号,计算出它的后继簇号的函数{unsigned long temp;struct FAT32_FAT *pFAT;struct FAT32_FAT_Item *pFAT_Item;temp=((LastCluster/128)+Init_Arg.FirstFATSector);//计算给定簇号对应的簇项的扇区号FAT32_ReadSector(temp,FAT32_Buffer);pFAT=(struct FAT32_FAT *)FAT32_Buffer;pFAT_Item=&((pFAT->Items)[LastCluster%128]);//在算出的扇区中提取簇项return lb2bb(pFAT_Item,4); //返回下一簇号}/*我们最终要实现的是对文件的读取,须要作到给定文件名后,可以得到相应文件的首簇。
音乐播放器的编程代码#include<windows.h>#include<mmsystem.h>#include<digitalv.h>#include<commctrl.h>#include<stdio.h>#include "resource.h"int GetFileName(TCHAR *FileName, HANDLE hwnd,char *lei){//该函数实现“打开文件名填充在FileName数组中,char *lei为需要打开的文件类型,如:mp3, 则传入"mp3"int i;int j;int len;char c[100]={0};char a[]="(*.)\0*.\0\0";OPENFILENAME FileNames;static char szFileName[MAX_PATH];static char szTitleName [MAX_PATH] ;static TCHAR szFilter[100] = {0};len = strlen(lei);c[0]=a[0];c[1]=a[1];c[2]=a[2];for(i=0;i<len;i++){c[3+i]=lei[i];}c[3+i]=a[3];c[4+i]=a[4];c[5+i]=a[5];c[6+i]=a[6];for(j=0;j<len;j++){c[7+i+j]=lei[j];}c[7+i+j]=a[7];c[8+i+j]=a[8];memcpy(szFilter, c,100);FileNames.lStructSize = sizeof (OPENFILENAME) ;FileNames.hwndOwner = hwnd ;FileNames.hInstance = NULL ;FileNames.lpstrFilter = szFilter ;FileNames.lpstrCustomFilter = NULL ;FileNames.nMaxCustFilter = 0 ;FileNames.nFilterIndex = 0 ;FileNames.lpstrFile = szFileName ;FileNames.nMaxFile = MAX_PATH ;FileNames.lpstrFileTitle = szTitleName ;FileNames.nMaxFileTitle = MAX_PATH ;FileNames.lpstrInitialDir = NULL ;FileNames.lpstrTitle = NULL ;FileNames.Flags = 0 ;FileNames.nFileOffset = 0 ;FileNames.nFileExtension = 0 ;FileNames.lpstrDefExt = NULL;FileNames.lCustData = 0 ;FileNames.lpfnHook = NULL ;FileNames.lpTemplateName = NULL ;GetOpenFileName(&FileNames);for(i=0,j=0; szFileName[i]; i++,j++){if(szFileName[i]=='\\'){FileName[j++] = szFileName[i];FileName[j]='\\';}elseFileName[j]=szFileName[i];}FileName[j] = 0;return 0;}LONG CALLBACKDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {static char FileName[250];static char buffer[100];static int iPosition;static HANDLE hSlider;static MCI_PLAY_PARMS mciPlay;static MCI_OPEN_PARMS mciOpen;static MCI_DGV_SETAUDIO_PARMS mciSetAudioPara;memset(FileName, 0, sizeof(FileName) );switch(message){case WM_CLOSE:EndDialog( hwnd, 0);return 0;case WM_INITDIALOG:hSlider = GetDlgItem(hwnd, IDC_SLIDER1);SendMessage(hSlider, TBM_SETPOS, TRUE, 20);mciSetAudioPara.dwValue = 200;mciSetAudioPara.dwItem = MCI_DGV_SETAUDIO_VOLUME;return 0;//音量调节的核心代码case WM_HSCROLL:switch(LOWORD(wParam) ){case SB_THUMBPOSITION:case SB_PAGERIGHT:case SB_PAGELEFT:iPosition = SendMessage(hSlider, TBM_GETPOS, 0, 0);mciSetAudioPara.dwItem = MCI_DGV_SETAUDIO_VOLUME;mciSetAudioPara.dwValue = iPosition*10;mciSendCommand(mciOpen.wDeviceID, MCI_SETAUDIO, MCI_DGV_SETAUDIO_V ALUE | MCI_DGV_SETAUDIO_ITEM,(DWORD)(LPVOID)&mciSetAudioPara);return 0;default:return 0;}return 0;case WM_COMMAND:switch(LOWORD(wParam) ){case IDB_SCAN:_GetFileName(FileName, hwnd, "mp3");//打开文件SetDlgItemText(hwnd, IDC_EDIT, FileName);SetFocus(GetDlgItem(hwnd, IDB_PLAY) );//开始播放mciOpen.lpstrElementName=(char *)malloc(250*sizeof(char));GetDlgItemText(hwnd, IDC_EDIT, mciOpen.lpstrElementName, 250);mciSendCommand(0, MCI_OPEN, MCI_OPEN_ELEMENT, (DWORD)&mciOpen);mciSendCommand(mciOpen.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mciPlay);//设置初始音量mciSendCommand(mciOpen.wDeviceID, MCI_SETAUDIO, MCI_DGV_SETAUDIO_V ALUE | MCI_DGV_SETAUDIO_ITEM,(DWORD)(LPVOID)&mciSetAudioPara);return 0;//从暂停中恢复播放case IDB_PLAY:mciSendCommand(mciOpen.wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)&mciPlay);return 0;//暂停case IDB_PAUSE:mciSendCommand(mciOpen.wDeviceID, MCI_PAUSE, MCI_NOTIFY, (DWORD)&mciPlay);return 0;default:return 0;}return 0;default:return 0;}}LONG WINAPIWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){InitCommonControls();DialogBoxParam(hInstance, IDD_DIALOG1, NULL, DlgProc,NULL);return 0;}。
网页MP3播放器代码如果你也想往自己的博客里,网页里加入音乐播放器,只要复制下面的网页音乐播放器代码,做适当的修改就可以啦!有很多播放器可以选择,不要挑花眼哦!中true或1表示自动播放,false或0表示手动播放loop="true" 中的true或1表示重复播放,false或0表示只播放一次width= height= 中的数字分别表示播放器的宽度和高度=0表示隐藏播放器EnableContextMenu="0" 禁右键ShowStatusBar="1" (带显示文件播放信息)1隐藏播放器(不循环)代码:<EMBED src=音乐网址 hidden=true type=audio/x-ms-wma >2.隐藏播放器(循环播放)代码:<EMBED src=音乐网址 hidden=true type=audio/mpeg loop="-1">3.黑色皮肤播放器代码:<EMBED style="FILTER: xray()" src=音乐网址width=360 height=30 type=audio/mpeg volume="0" loop="-1">4.淡蓝色播放器代码:<EMBED src=播放地址 width=300 height=45 type=audio/mpeg loop="-1" volume="0">5.迷幻播放器代码:<TABLE style="FILTER: Alpha(Opacity=100, FinishOpacity=0, Style=2, StartX=20, StartY=40, FinishX=0, FinishY=0)gray(); WIDTH: 400px; HEIGHT: 83px"><TBODY><TR><TD><EMBED src=播放地址 width=400 height=40 type=audio/mpeg panel="0" loop="true"></TD></TR></TBODY></TABLE>6.带菜单的播放器代码:<EMBED pluginspage=/windows/mediaplayer/download/default.asp width=400 height=172 type=application/x-mplayer2 FileName="音乐网址" SHOWCONTROLS="1" SHOWSTATUSBAR="1" SHOWDISPLAY="1" SHOWGOTOBAR="1" PlayCount="1">7.深黄色带菜单播放器代码:<EMBED style="FILTER: invert()" src=音乐网址 width=320 height=45 type=audio/x-ms-wma ShowStatusBar="1" loop="true" >8.灰色播放器代码:<EMBED style="FILTER: Gray()" src="链接地址" width=300 height=69 type=application/x-mplayer2 loop="-1" showcontrols="1" ShowDisplay="0" ShowStatusBar="1" ></EMBED>9.灰白色播放器代码:<embed style="FILTER: Gray()" src=链接地址 width=300 height=45 loop="-1" ></EMBED>10.带菜单的蓝色播放器代码:<EMBED src="链接地址" width=300 height=69 type=application/x-mplayer2 loop="-1" showcontrols="1" ShowDisplay="0" ShowStatusBar="1" ></EMBED>11.棕色播放器代码:<EMBED style="FILTER: invert()" src=链接地址 width=300 height=45 loop="-1" ></EMBED>12.带边框背景的播放器代码:<TABLE borderColor=#4F3256 background=背景图片地址 border=1><TBODY><TR><TD style="FILTER: alpha(opacity=50,style=3)"><P align=center><EMBED src=音乐网址width=300 height=25 type=audio/mpeg loop="-1" volume="0"></P></TD></TR></TBODY></TABLE>13.带背景图片的播放器代码:<TABLE borderColor=navy background=图片地址 border=0><TBODY><TR><TD style="FILTER: alpha(opacity=80,style=3)"><P align=center><EMBED src=音乐网址width=300 height=45 type=audio/mpeg loop="-1" volume="0"></P></TD></TR></TBODY></TABLE>12 13综合属性分析background=图片地址可以更换图片地址来实现改变播放器背景14.黄色闪光播放器代码:<TABLE style="BORDER-RIGHT: #000000 3px dashed; BORDER-TOP: #000000 3px dashed; BORDER-LEFT: #000000 3px dashed; BORDER-BOTTOM: #000000 3px dashed" cellSpacing=0 cellPadding=0bgColor=#00000><TBODY><TR><TD><TABLE borderColor=navybackground=/s-helpSite/domName/nxm/20041114123131568.gif border=0><TBODY><TR><TD style="FILTER: alpha(opacity=50,style=3)"><P align=center><EMBED src=音乐网址 width=400 height=35 type=audio/mpeg loop="-1" loop="-1"> </P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>15.蓝色闪光播放器代码:<TABLE borderColor=#dee4fe cellSpacing=3 cellPadding=0background=/UploadFile/2004-12/2004123023101352.gifborder=2><TBODY><TR><TD><TABLE align=center border=0><TBODY><TR><TD style="FILTER: alpha(opacity=60,style=3)"><P align=center><EMBED style="FILTER: Gray" src=音乐网址 width=400 height=35 type=audio/mpeg volume="0" loop="-1"></P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>16.带花边的播放器代码:<TABLE style="BORDER-RIGHT: #000000 3px dashed; BORDER-TOP: #000000 3px dashed; BORDER-LEFT: #000000 3px dashed; BORDER-BOTTOM: #000000 3px dashed" cellSpacing=0 cellPadding=0bgColor=#00000><TBODY><TR><TD><TABLE borderColor=#000000 align=center border=1><TBODY><TR><TD><P align=center><EMBED style="FILTER: Xray" src=音乐网址 width=400 height=35 type=audio/mpeg volume="0" loop="-0"></P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>17.粉色花边播放器代码:<TABLE style="BORDER-RIGHT: #ff69b4 3px dotted; BORDER-TOP: #ff69b4 3px dotted; BORDER-LEFT: #ff69b4 3px dotted; BORDER-BOTTOM: #ff69b4 3px dotted" cellSpacing=0 cellPadding=0 align=center bgColor=white><TBODY><TR><TD><TABLE borderColor=#ff69b4 align=center bgColor=#ffccf5 border=2><TBODY><TR><TD style="FILTER: alpha(opacity=100,style=3)"><P align=center><EMBED src=音乐网址 width=300 height=25 type=audio/mpeg volume="0"loop="-0"></P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>18.显示文件标签灰色播放器代码:<DIV><EMBED style="FILTER: Gray()" src="链接地址" loop="-1" width=300 height=140 balance="true" showpositioncontrols="true" showtracker="true" showaudiocontrols="true" showcontrols="true" showstatusbar="true" showdisplay="true" displaysize="0" volume="100" animationatstart="true" transparentatstart="true"></EMBED></div>19显示文件标签棕色播放器代码:<DIV><EMBED style="FILTER: invert()" src="链接地址" loop="-1" width=300 height=140 balance="true" showpositioncontrols="true" showtracker="true" showaudiocontrols="true" showcontrols="true" showstatusbar="true" showdisplay="true" displaysize="0" volume="100" animationatstart="true" transparentatstart="true"></EMBED></div>20.显示文件标签黑色播放器代码:<DIV><EMBED style="FILTER: xray()" src="链接地址" loop="-1" width=300 height=140 balance="true" showpositioncontrols="true" showtracker="true" showaudiocontrols="true" showcontrols="true"showstatusbar="true" showdisplay="true" displaysize="0" volume="100" animationatstart="true" transparentatstart="true"></EMBED></div>21.连放播放器代码:<EMBED style="FILTER: Gray()" src=音乐网址 width=500 height=35 type=audio/x-ms-wma controls="StatusBar,TACCtrl,ControlPanel" border="0" playcount="0" showtracker="1"volume="0"></EMBED>22.彩色播放器代码:<TABLE style="FONT-WEIGHT: normal; FONT-SIZE: 12px; COLOR: 00CCFF; FONT-STYLE: normal; FONT-FAMILY: Tahoma, Verdana; FONT-VARIANT: normal" cellSpacing=0 cellPadding=0 width=140 border=0><TBODY><TR><TD style="BACKGROUND-COLOR: 00CCFF"><EMBED style="FILTER: invert alpha(opacity=50) WIDTH: 140px; HEIGHT: 45px" src=音乐链接地址 type=video/x-ms-asf loop="-1"volume="0"></EMBED></TD></TR></TBODY></TABLE>本代码属性分析BACKGROUND-COLOR: 00CCFF播放器颜色代码可以更换以变换播放器颜色23.透明播放器代码代码:<TABLE style="FILTER: Alpha(Opacity=100, FinishOpacity=0, Style=2, StartX=20, StartY=40, FinishX=0, FinishY=0)xray(); WIDTH: 200px; HEIGHT: 40px"><TBODY><TR><TD><EMBED style="BORDER-RIGHT: silver 1px solid; BORDER-TOP: silver 1px solid; BORDER-LEFT: silver 1px solid; BORDER-BOTTOM: silver 1px solid" src=音乐链接地址 width=200 height=30type=audio/x-mplayer2 loop="-1" volume="0" EnableContextMenu="0" showstatusbar="0" console="video"></TD></TR></TBODY></TABLE>。
mp3文件播放器源代码头文件代码(resource。
H)
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by Script1.rc
//
#define IDI_ICON1 101
#define IDI_MAINICON 101
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONL Y_SYMBOLS
#define _APS_NEXT_RESOURCE_V ALUE 102
#define _APS_NEXT_COMMAND_V ALUE 40001
#define _APS_NEXT_CONTROL_V ALUE 1000
#define _APS_NEXT_SYMED_V ALUE 101
#endif
#endif
主程序代码(main)
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <dshow.h>
#pragma comment( lib, "Strmiids.lib")
#pragma comment( lib, "winmm.lib" )
#define V_RETURN(x) { hr = x; if( FAILED(hr) ) { return hr; } }
//////////////////////////////////////////////////////////////////////////
//变量定义:
IGraphBuilder* pGBuilder;
IMediaPosition* pMPos;
//////////////////////////////////////////////////////////////////////////
HRESULT InitDirectShow()
{
HRESULT hr;
CoInitialize(NULL); //初始化COM
//创建各个对象
CoCreateInstance(CLSID_FilterGraph, NULL,
CLSCTX_INPROC, IID_IGraphBuilder, (void**)&pGBuilder);
V_RETURN(pGBuilder->QueryInterface(IID_IMediaControl, (void**)&pMControl));
V_RETURN(pGBuilder->QueryInterface(IID_IMediaPosition, (void**)&pMPos));
return S_OK;
}
HRESULT LoadMusicFile(const char *path)
{
HRESULT hr;
CHAR strSoundPath[MAX_PATH]; //存储音乐所在路径
WCHAR wstrSoundPath[MAX_PATH]; //存储UNICODE形式的路径
strcpy(strSoundPath, path);
MultiByteToWideChar(CP_ACP, 0, strSoundPath, -1,wstrSoundPath, MAX_PATH);
V_RETURN(pGBuilder->RenderFile(wstrSoundPath, NULL)); //调入文件
return S_OK;
HRESULT Play()
{
HRESULT hr;
//播放MP3的方法十分简单:
return S_OK;
}
HRESULT Stop()
{
//最后,我们要停止播放音乐并释放各个对象:
V_RETURN(pMControl->Stop()); //停止播放
return S_OK;
}
void FreeDirectShow()
//释放对象
CoUninitialize(); //释放COM
}
//////////////////////////////////////////////////////////////////////////
int main()
{
char cmd[255] = {NULL}, path[MAX_PATH] = {NULL};
if(FAILED(InitDirectShow()))
{
getch();
return 1;
}
while(1)
{
printf("*****这个是用于制作游戏的音乐播放程序,由于时间关系和便于学习我不printf("使用方法--输入以下命令:\n#载入并播放音乐:play\n#停止播放:
scanf("%s", cmd);
if(!stricmp(cmd, "play"))
{
printf("请输入文件名:");
printf("正在处理命令...\n", cmd, path);
if(FAILED(LoadMusicFile(path)))
{
getch();
path[0] = 0;
}
else Play();
else
{
printf("正在处理命令...\n", cmd, path);
if(!stricmp(cmd, "replay"))
{
Stop();
}
else if(!stricmp(cmd, "stop"))
Stop();
else if(!stricmp(cmd, "exit"))
goto quit;
else
{
printf("无法识别的命令");
getch();
}
}
quit:
FreeDirectShow();
}。