Skip to main content

C++ = How to Play audio on C++

                                                                    Assalam-u-Alaekum

For creating Music Player, We need some initial things to know:

First of all, Create a project and save it, start typing code in it after that before compiling and running it

You have go to Project (option) and then Project option.

After that go to parameters and then go to Linker and write "-lwinmm" in it. Hit OK

Save the file and compile it.

NOTE:  In the code PlaySound, After TEXT code you can write path for the song and name also.

SONG PATH: When song is in different directory.

SONG NAME: When song is present with source code. 


Source Code:

#include <iostream>

#include <windows.h>

#include <mmsystem.h>

using namespace std;

int main()

{

int input;

cout<<"                         Welcome To Our Music Player"<<endl;

cout<<endl;

cout<<"Press 1 for Hairun Khairun Music : "<<endl;

cout<<"Press 2 for Mask Off Music : "<<endl;

cout<<"Press 3 for In the End Music : "<<endl;

 

cout<<"Press 4 for Childhood Music : "<<endl;

 

cout<<"Press 5 for Amrof Col Music : "<<endl;

 

cout<<"Press 6 for Swaha x Faded Music : "<<endl;

 

cout<<"Press 7 for Yalan Music : "<<endl;

 

cout<<"Press 8 for Kavakaz Music : "<<endl;

 

cout<<"Press 9 for Uzak Volin Music : "<<endl;

 

cout<<"Press 10 for Drive Forever Music : "<<endl;

cout<<"   "<<endl;

cout<<"  "<<endl; 

cout<<"Enter number of desired music : ";

cin>>input;

cout<<""<<endl;

cout<<"Playing Song.........."<<endl;

if (input==1)

PlaySound(TEXT("HariunKhairun.wav"),NULL,SND_SYNC);

else if (input==2)

PlaySound(TEXT("Mask Off Remix - Tupac Mask Off.wav"),NULL,SND_SYNC);

else if (input==3)

    PlaySound(TEXT("in_the_end.wav"),NULL,SND_SYNC);

    else if (input==4)

    PlaySound(TEXT("childhood.wav"),NULL,SND_SYNC);

    else if (input==5)

    PlaySound(TEXT("Amrof_col.wav"),NULL,SND_SYNC);

    else if (input==6)

    PlaySound(TEXT("Swaha X Faded Ringtone by ROYAL MUSIC MANIA.wav"),NULL,SND_SYNC);

    else if (input==7)

    PlaySound(TEXT("Yalan_Dunya.wav"),NULL,SND_SYNC);

    else if (input==8)

    PlaySound(TEXT("Kavakaz.wav"),NULL,SND_SYNC);

    else if (input==9)

    PlaySound(TEXT("Uzak Violin - Uzak Violin Beat Mix - Bgm.wav"),NULL,SND_SYNC);

    else if (input==10)

    PlaySound(TEXT("Drive_Forever_Remix.wav"),NULL,SND_SYNC);

    

    else 

cout<<"Invalid Entry"<<endl;

    

    cout<<"Song stopped"<<endl;

return 0; 

                                                                

}

Comments

Popular posts from this blog

C++ = Code for Counter

Code: #include <iostream> #include <conio.h> using namespace std; int main() {     int count = 0;     char input;     cout << "--------------------------" << endl;     cout << "          Counter         " << endl;     cout << "--------------------------" << endl;     cout << endl;     cout << "Press 1 to counter" << endl;     cout << "Press 0 to quit" << endl;     cout << endl;     cout << "Enter the number continuously : ";     while (true)     {         input = getch();         if (input == '1')         {             count += 1;             cout << "Your counts are " << count << endl;   ...

C++ = Code to check number is a prime or not. If not find the nearest prime number.

Code:  #include <iostream> using namespace std; bool prime(int n) { if (n<=1) { return false; }        for (int i=2;i<=n/2;i++)    {       if (n%i==0)   {   return false;   }    }         return true; } int nearest(int n) { for (int i=n-1;i>=2;i--) { if (prime(i)) { return i; } } return 0; } int main () { int number; cout<<"Enter any number : "; cin>>number; if (prime(number)) { cout<<"The number is prime. "<<endl; }     else     {     cout<<"The entered number is compositive."<<endl;     cout<<"The nearest prime number will be "<<nearest(number)<<endl; } } Result:

C++ = Code for checking any digit palindrome number

Code no: 1 = Using only main function to perform task. #include <iostream> using namespace std; int main() { int number,original,digit,reverse=0; cout<<"Enter any number : "; cin>>number; original=number; while (number!=0) { digit=number%10; reverse=(reverse*10)+digit; number=number/10; } if (original==reverse) { cout<<"This "<<original<<" is Palindrome number."; } else { cout<<"The "<<original<<" is not Palindrome number."; } } Result: Code no: 2 = Using two functions to perform same task. #include <iostream> using namespace std; int isprime(int num) { int digit=0,reverse=0; while (num!=0) { digit=num%10; reverse=(reverse*10)+digit;  num/=10; } return reverse; } int main() { int num; cout<<"Enter any digit to find its sum = "; cin>>num;          int original=num;          if (i...