#include<stdio.h>
#include<windows.h> 定義DWORD#include<mmsystem.h> playSoundA
int main()
{
PlaySoundA("abc.wav",NULL,SND_SYNC);
printf("Week11\n");
}
加入按鈕進行播放
#include <stdio.h>
#include <windows.h>
#include <mmsystem.h>
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
void mouse(int button, int state, int x, int y)
{
if(state==GLUT_DOWN)PlaySoundA("abc.wav",NULL,SND_SYNC);
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE |GLUT_DEPTH);
glutCreateWindow("week11");
glutMouseFunc(mouse);
glutDisplayFunc(display);
glutMainLoop();
}
MP3播放
#include <stdio.h>
#include <GL/glut.h>
#include <windows.h>
#include <mmsystem.h>
#include "CMP3_MCI.h"///雙引號,表示要在同一個專案目錄找
CMP3_MCI myMP3;///宣告一個物件變數 myMP3
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
void mouse(int button, int state ,int x ,int y)
{
if(state==GLUT_DOWN) PlaySoundA("Sword.wav",NULL, SND_SYNC);
}
int main(int argc, char **argv)
{
myMP3.Load("BGM.mp3");///讀入檔案,小心執行目錄 (in....)
myMP3.Play();///播放
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week12 Sound");
glutMouseFunc(mouse);
glutDisplayFunc(display);
glutMainLoop();
}


沒有留言:
張貼留言