play audio song in background of my project

i want to play the audio tone(song), when my project GUI run ,,i have 3 GUI of my project which are linked with each other ,,...i want tooo play tone in background until my project is run.. can any on ehelp meee how can i play:

2 件のコメント

Joakim Magnusson
Joakim Magnusson 2014 年 8 月 14 日
What format is the sound file?
reema
reema 2014 年 8 月 14 日
sound in mp3 or format or wav form

サインインしてコメントする。

 採用された回答

Joakim Magnusson
Joakim Magnusson 2014 年 8 月 14 日
編集済み: Joakim Magnusson 2014 年 8 月 14 日

0 投票

If you have a .wav file i think this will work. First load your file:
[y f]=audioread('yourMusicFile.wav');
Then play audio with:
sound(pl);
Stop sound with:
clear playsnd;

28 件のコメント

reema
reema 2014 年 8 月 14 日
its work wwith his code ...but now tell me i want to stop this song in spacific palace (when me pushbutton click)..now how can i do this?
[y f]=audioread('21.mp3');
sound(y,f);
reema
reema 2014 年 8 月 14 日
orr can i repeat this song until project last GUI is open..when GUI is exit then song shold be stop
Joakim Magnusson
Joakim Magnusson 2014 年 8 月 14 日
I edited the answer, does it work?
reema
reema 2014 年 8 月 14 日
yes its work..but little bit enhancement i do
reema
reema 2014 年 8 月 14 日
can i repeat the song until my last GUI is open ..when last GUI is exit then song is stop...or pushing any button the song will stop
reema
reema 2014 年 8 月 14 日
sorry i didn't see the edit part
Joakim Magnusson
Joakim Magnusson 2014 年 8 月 14 日
編集済み: Joakim Magnusson 2014 年 8 月 14 日
Like Sean answered, try audioplayer:
player = audioplayer(y,f);
play(player);
pause(player);
resume(player);
stop(player);
reema
reema 2014 年 8 月 14 日
no its not work.... thsi code didin;t play the song even: my code is playthe song given below:
[y f]=audioread('21.mp3');
sound(y,f);
reema
reema 2014 年 8 月 14 日
ok i try sean answer
Joakim Magnusson
Joakim Magnusson 2014 年 8 月 14 日
This doesn't work you say?:
[y f]=audioread('21.mp3');
player = audioplayer(y,f);
play(player);
reema
reema 2014 年 8 月 14 日
no itss not work.. i can;t hear the song even:
Joakim Magnusson
Joakim Magnusson 2014 年 8 月 14 日
i think the handle to the player disappear after the callback and therefore the audioplayer disappear. try:
persient player;
[y f]=audioread('21.mp3');
player = audioplayer(y,f);
play(player);
or this is just a guess but maybe just:
[y f]=audioread('21.mp3');
handles.player = audioplayer(y,f);
play(player);
reema
reema 2014 年 8 月 14 日
noo doingg nothinggg... i can play the song but i can't stop it..when me want
reema
reema 2014 年 8 月 14 日
i got the ans ...if we stop the music then simplyy
clear sound;
its wok with my code not with audioplayer's code
reema
reema 2014 年 8 月 14 日
joakim sir i need some professional tones which me able to play in background of my project when its run ..can you help me? give any link for download professional tones
Joakim Magnusson
Joakim Magnusson 2014 年 8 月 14 日
Doesn't this work with audioplayer? :
stop(player);
What do you mean with profesional tones ?
reema
reema 2014 年 8 月 15 日
i have a project i want to playback the tone when its run ...soo its a project so the tone should be anyy profeesional
reema
reema 2014 年 8 月 15 日
okay let me check this stop(player);
reema
reema 2014 年 8 月 15 日
noo itss nott work with matlab R2013a ..i don't knw about other versions.. its nott workk when we apply this code :
[y, f]=audioread('21.mp3');
player = audioplayer(y,f);
play(player);
then we can't hear the song even...
reema
reema 2014 年 8 月 15 日
and when we use stop(player); the errror show
Undefined function or variable 'player'.
Error in Face_Detection_And_Recognition>pushbutton1_Callback (line 106)
stop(player);
Joakim Magnusson
Joakim Magnusson 2014 年 8 月 16 日
Like i said , you must "save" the handle to the audioplayer. Either by this at the begining of your code:
persient player;
Or by this whey you create the audioplayer:
handle.player = audioplayer (Y, f);
reema
reema 2014 年 8 月 16 日
no sir, when me use this presient code then error show undefine function presient....its not work with matlab r2013a
Joakim Magnusson
Joakim Magnusson 2014 年 8 月 16 日
編集済み: Joakim Magnusson 2014 年 8 月 16 日
What happens when you use handle? Without using persient.
reema
reema 2014 年 8 月 16 日
firstly show the error undefine function presient
reema
reema 2014 年 8 月 16 日
its perfectly work with sound's code then why we use audioplayer
reema
reema 2014 年 8 月 16 日
when me use this code your recommended:
[y f]=audioread('21.mp3');
handles.player = audioplayer(y,f);
play(player);
then error show:
Undefined function or variable 'player'.
Error in Face_Detection_And_Recognition>Face_Detection_And_Recognition_OutputFcn (line 100)
play(player);
reema
reema 2014 年 8 月 16 日
and when me use this code also your recommended:
persient player;
[y f]=audioread('21.mp3');
player = audioplayer(y,f);
play(player);
then error show:
Undefined function 'persient' for input arguments of type 'char'.
Error in Face_Detection_And_Recognition>Face_Detection_And_Recognition_OutputFcn (line 96)
persient player;
reema
reema 2014 年 8 月 16 日
sir do you have any idea about voice effects in matlab? i want to generate voice with effect...i have simple recorded voice and want to hear in voice efects(sound effects)..

サインインしてコメントする。

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2014 年 8 月 14 日

0 投票

audioplayer can play without play blocking (so your other processes and continue).

3 件のコメント

reema
reema 2014 年 8 月 14 日
i can't get your point please elabrate
Sean de Wolski
Sean de Wolski 2014 年 8 月 14 日
When you play a song with sound, it blocks audioplayer does not so you can have your code running.
Read the example in the doc linked or at:
doc audioplayer
reema
reema 2014 年 8 月 14 日
but when me use the audioplayer then i can;t hear the song

サインインしてコメントする。

タグ

質問済み:

2014 年 8 月 14 日

コメント済み:

2014 年 8 月 16 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by