2023年4月26日 星期三

翁逸豪 Week11

Week11-1

利用鍵盤控制小黑視窗

 keyboard(unsigned char key, int x, int y)

{

    if(key==27) exit(0);

}

按下Esc鍵,結束並顯示0

顯示茶壺
結束顯示0

Week11-2

播放聲音

#include <windows.h>

void keyboard(unsigned char key, int x, int y)

{

    if(key=='1') PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\do.wav",NULL,SND_ASYNC);

    if(key=='2') PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\re.wav",NULL,SND_ASYNC);

    if(key=='3') PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\mi.wav",NULL,SND_ASYNC);

}

使用絕對位置找出音檔並撥放,絕對位置的 \ 要改成 \\

 ㄜㄜㄜ......圖片沒有聲音

Week11-3

播放聲音,這次要撥放的位置是相對位置,因此要先做設定

設定

設定完之後再打上程式

#include <windows.h>

int main()

{

    PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\do.wav",NULL,SND_SYNC);

    PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\fa.wav",NULL,SND_SYNC);

    PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\mi.wav",NULL,SND_SYNC);

    PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\re.wav",NULL,SND_SYNC);

    PlaySound("C:\\Users\\Administrator\\Desktop\\do_re_mi\\so.wav",NULL,SND_SYNC);

}

一樣是沒有聲音的圖片

Week11-4

播放絕對路徑mp3檔,執行前必須先將CMP3_MCI.h檔案加入GLUT程式資料夾
CMP3_MCI.h加入GLUT程式資料夾
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
int main(int argc, char *argv[])
{
    char filename[] = "C:/Users/Administrator/Desktop/do_re_mi/suzumi.mp3";
    myMP3.Load(filename);
    myMP3.Play();
}
還是沒有聲音的圖片

播放相對路徑mp3檔,執行前必須先將 CMP3_MCI.h 、 freeglut.dll 、 音檔 加入GLUT程式資料夾
加入資料夾

更改.cbp檔裡面的內容
更改內容
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
int main(int argc, char *argv[])
{
    myMP3.Load("suzumi.mp3");
    myMP3.Play();
}
最後一張沒有聲音的圖片

沒有留言:

張貼留言