How do I play a sound?
How do I play sound?
It depends on the duration of the sound and how often it will be used. For sound effects less that 5 seconds, the System Sound methods in the AudioToolbox framework are a good choice. I'm just now trying to remember the sample project that has the best sample code for this purpose. It will be easier to just paste in my own class:
// SoundEffect.h
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
@interface SoundEffect : NSObject {
SystemSoundID ssId;
-(id)initWithFileName:(NSString*)name andExt:(NSString*)ext;
-(void)playSound;
@end
// SoundEffect.m
#import "SoundEffect.h"
@implementation SoundEffect
-(void)playSound {
AudioServicesPlaySystemSound(ssId);
-(id)initWithFileName:(NSString*)name andExt:(NSString*)ext {
if (![super init])
return nil;
// NSLog(@"initWithFileName: %@.%@", name, ext);
// Get path inside appl package
NSString *resPath = [[NSBundle mainBundle] pathForResource:name ofType:ext];
if (resPath == nil) {
NSLog(@"resPath = nil");
return nil;
// NSLog(@"resPath = %@", resPath);
NSURL *myURLRef = [NSURL fileURLWithPath:resPath isDirectory:NO];
// NSLog(@"myURLRef = %@", myURLRef);
OSStatus ossCode = AudioServicesCreateSystemSoundID ((CFURLRef)myURLRef, &ssId);
if (ossCode) {
NSLog(@"ossCode = %X", ossCode);
return nil;
return self;
-(void)dealloc {
OSStatus ossCode = AudioServicesDisposeSystemSoundID (ssId);
if (ossCode)
NSLog(@"dealloc: ssId ossCode = %X", ossCode);
[super dealloc];
@end
Both the simulator and the device will decide they don't like certain sounds. That can be confusing because it's not uncommon to be able to play a sound on the simulator that won't play on the device, and vice-versa. When that happens you'll see an error code in the console (uncomment more of the logging to see the whole story). I forgot the code for an unacceptable format, but you'll learn it soon enough. Often the solution is to just convert the file to a different format. When I was trying out the sounds that came with OS X, I found that the device didn't like any of the .caf files. It couldn't play those sounds until I opened the files in Audacity® and resaved them as a different size .caf.
Hope that helps!
- Ray
Similar Messages
-
TS4006 how to I play a sound on my phone to locate it?
how do I play a sound on my phone to locate it???
Using a computer's browser log into icloud.com, or using another device, download the Find My iPhone app from the app store and log in.
For the device that's lost, tap the "Play sound" button. -
How do i play two sound file one after another
Hi All,
How do i play two sound file one after another using single AudioClip Component?.
Advance in thanks
ManivelAudioClip gives you very little control over what happens to the sound, it also isn't capable of playing long clips or waiting until a clip ends. It will play multiple clips over top of each other.
To do what you want you should use the facilities of javax.sound. Here's a post with an example: http://forum.java.sun.com/thread.jspa?forumID=513&threadID=450768
There is also a tutorial, but its example fails for long clips. -
Please tell me how to automatically play a sound file in a PDF slideshow?Da
I use PS CS3, LR2, and now I purchased Acrobat 9.1 Pro. My intent is to create an image based full screen automatic slideshow WITH SOUND. I have everything working well but I can't figure out how to get the sound file to simply play along with the images. I do not want the viewer to have to press anything to hear the sounds. The sound file should simply play along with the image(s). I would like to be able to time the sound file to the images as well.
I will appreciate any pointers you may have.
Thanks...To do this reliably the document has to be in the list of the client applications list of trusted documents. You get this prompt when you attempt to play a sound. The other way is to actually set the Multimedia Trust (legacy) preference on each client for each type of Player application. While this might seem a bit of a task it's meant to protect the user.
-
How do you play multiple sounds simultaneously and synchronized?
lets say I have two wave files that are similar in play length but not quite the same. I calculate a new frame rate for reach to make their lengths almost perfectly the same. Now I want to play them and have them repeat for a while.. If I don't synchronize them in some fashion, inevitably the slight difference in play time will cause them to unsync.
what's the best way to keep them in sync? I've been trying playing each sound in it's own thread for the past few days and using thread synchronization, but that isn't working so well.
thanks for the help.I found the answer I'm looking for! version 1.5 came out with the CyclicBarrier class that causea a thread to pause when it calls the barriers await() function until a predetermined number of threads call await().
So I can create a barrier of size (ThreadCount) and tell all threads to pause at the beginning of a measure until all threads have checked in. That way all threads are out the gate at the same time every measure. -
How can i Play a sound in iPhone?
in the application to play a sound file,use which API?who can tell me.
AudioServicesPlaySystemSound in AudioToolbox framework.
-
How can i play a sound file in form 10g
hi every body ,
would any one help me with my problem
*I 'd like to play a soend wave file _ say when press a button _*
In forms 6i
it was too easy,
Read_sound_File('c:\aaa.wav', 'wav', 'emp.sound');
Go_Item('emp.sound ');
play_sound('emp.sound');
But it doesn't work in 10g
and there is n't read_sound_file in help of 10g
is there any compatability with this instruction in forms 10g
or how can i use sound file in 10g
is it with webUtil ( i' ve configured it correctly )
*or with java beans _ plz help me with it _*
Thanks _ waiting for u answers _ plzzzzzzzzzzzzzzzzI 'd like to play a soend wave file _ say when press a button package sound;
import oracle.forms.ui.VButton;
import java.applet.AudioClip;
import java.applet.Applet;
import java.net.URL;
import oracle.forms.properties.ID;
public class sound extends VButton
public final static ID PLAY = ID.registerProperty("PLAY");
public String sou_loc = "FILE:///C:\EAM_original.wav" ;
public sound()
public boolean setProperty(ID p0, Object p1)
if (p0==PLAY)
{ try
sou_loc = p1.toString();
URL sou = new URL(sou_loc);
AudioClip clip = Applet.newAudioClip(sou);
clip.play();
} catch (Exception ex)
{ex.printStackTrace();}
return super.setProperty(p0, p1);
} -
How do I play a sound when a popup window opens.
I don't want to block the popup. It's just a notice of a timeout for a site I frequent. I want to enable a sound to play when the popup appears so I know the site is about to time out. I'm using Firefox 35.0.1 on a MacBook. Thanks in advance for any help!
You may need an add on or third party software for this.
-
Hello!
How can I play multiple sounds at once please?
I tried with 2 separate soundChannel vars but they still override eachother.
Thanksplay both sounds through the same sound channel? eg:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
private var sound:Sound;
private var soundChannel:SoundChannel;
private function play1():void
sound = new Sound();
sound.load(new URLRequest("sounds/1.mp3"));
sound.addEventListener(Event.COMPLETE, songLoaded);
private function play2():void
sound = new Sound();
sound.load(new URLRequest("sounds/2.mp3"));
sound.addEventListener(Event.COMPLETE, songLoaded);
private function songLoaded(e:Event):void
try
sound.removeEventListener(Event.COMPLETE, songLoaded);
soundChannel = sound.play(0);
catch(err:Error)
trace(err)
]]>
</mx:Script>
<mx:Button x="140" y="313" label="Play sound 1" click="play1()"/>
<mx:Button x="229" y="326" label="Play sound 2" click="play2()"/>
</mx:Application> -
How do I play an audio file in Xcode for Mac OS X?
I have been looking and looking, and I still can't find out how I can play a sound in Xcode. I have done it for the iPhone, but I'm trying to do it for Mac OS X. I am a beginner and so I am going to need some explaining as to what is going on. I just need to play a short sound (max of 10 seconds) when a timer goes off. Any help is very greatly appreciated (I have been trying to get this to work for WEEKS)! Thanks in advance.
https://developer.apple.com/mac/library/samplecode/PlayFile/Introduction/Intro.h tml
Docs are your friend....mac os has it's own just like iPhone. -
as the tile said, I use my ipad as usual. no dock connector is installed.
but i found that "Dock Connector" is always displayed in iPod.
is that the problem of connector?
too bad, i don't even drop or bumb my ipad into hard surface. how come it play no sound with the internal speaker!?
"Dock Connector?"
Brothers, please help , thanks alot !Welcome to Apple Discussions!
First, make sure everything is up to date...
iTunes
iPod Updater
Updating iPod's Software
See if either of these help the sound issue...
Resetting iPod
Restore the iPod
To delete photos, delete them from the folder the iPod is updating from. I have my photo library organized on my computer, and didn't want to change it for the iPod. So, I created a folder called "iPod Pics." Under the photo preferences for the iPod, I told iTunes to sync from there. I just put in and remove photos that I want for my iPod there. This way, I don't need to edit the My Pictures folder just for my iPod.
btabz -
I have rented a video and when I go to play it on apple tv from my iphone it only plays the sound, how do I fix this?
if it's not iphone4s or later it does not support airplay mirror
-
How can I play music on my macbook pro (OSX Lion) through a Pioneer receiver? I've connected them with a mini display port to HDMI cable with audio support bought at the Apple Store, but there's no sound coming through. There are 4 HDMI-in ports on the receiver - BD, DVD, DVR/BDR and audio. In my system preferences for sound, the receiver doesn't show up as an output option. Can anyone please advise. (ps, this is my first time posting a question, so I hope I can find your answers!) thanks, JP downunder
For sound, try the audio output port and connecting to the RCA audio input ports on your Pioneer receiver. Use something like this:
http://eshop.macsales.com/item/OWC/PODCONNECTOR/
Ciao. -
How do i play sound in java??
hello,
How do i play sound in java??
im new to java
thanks,There are crude abilities to play sound in the core of java. If you really want to make good sound apps though you should look at the JMF.
http://java.sun.com/products/java-media/jmf/ -
How do I stop a sound file that is playing while Firefox is open that sounds like a PacMan Game? It started when I downloaded the current Adobe DLM, but continues when disable. It begins playing each time I open FireFox, but gets interferred with when opening a web page.
== This happened ==
Every time Firefox opened
== 1520 hours, Central TimeSee [[Firefox makes random sounds]]
Maybe you are looking for
-
My macbook pro retina wont recognize my external hard drive
my macbook pro retina wont recognize my external hard drive. i opned the hard drive in the past on my computer and used it alot. one time when i took it out i forgot to eject it, and since then when ever i conect it it would never show up on my compu
-
"Closed" security model in BOXI 3.0
Hello, Is it possible to create a closed security model in BOXI 3.0? In BOXI R2 we simply set the everyone group to no access in the settings area. I do not see the same functionality in 3.0. Am I missing something? Thanks
-
Unable to parse information Error while logging in to BPC 4.2 Web Excel
Hi, I am not able to Log In to BPC 4.2 WebExcel. I am getting a Error Message saying that "unable to parse information". I am actually logging in after long time and before i use to log in successfully. I checked with security and every thing is fin
-
Trying to update iTunes on Windows XP, get error message "The older version of Bonjour cannot be removed." I have removed several copies of the file Bonjour in a couple of different folders but the error message persists. What am I missing??
-
Enable Profile (ACR) and Filter Lens Corrections does not recognize Lens
I did several searches and couldn't find this so it may be a new question. I'm running into it in both CS5 (Camera Raw and Filter > Lens Corrections) and Lightroom 3.3 (Develop- Enable Profile). I'm asking here since I figure if I can fix CS5, I'll k