You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
play audio song in background of my project
19 views (last 30 days)
Show older comments
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:
Accepted Answer
Joakim Magnusson
on 14 Aug 2014
Edited: Joakim Magnusson
on 14 Aug 2014
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 Comments
Joakim Magnusson
on 14 Aug 2014
I edited the answer, does it work?
Joakim Magnusson
on 14 Aug 2014
Edited: Joakim Magnusson
on 14 Aug 2014
Like Sean answered, try audioplayer:
player = audioplayer(y,f);
play(player);
pause(player);
resume(player);
stop(player);
Joakim Magnusson
on 14 Aug 2014
This doesn't work you say?:
[y f]=audioread('21.mp3');
player = audioplayer(y,f);
play(player);
Joakim Magnusson
on 14 Aug 2014
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);
Joakim Magnusson
on 14 Aug 2014
Doesn't this work with audioplayer? :
stop(player);
What do you mean with profesional tones ?
reema
on 15 Aug 2014
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...
Joakim Magnusson
on 16 Aug 2014
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);
Joakim Magnusson
on 16 Aug 2014
Edited: Joakim Magnusson
on 16 Aug 2014
What happens when you use handle? Without using persient.
reema
on 16 Aug 2014
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
on 16 Aug 2014
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;
More Answers (1)
Sean de Wolski
on 14 Aug 2014
audioplayer can play without play blocking (so your other processes and continue).
3 Comments
Sean de Wolski
on 14 Aug 2014
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
See Also
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)