is there a way to adjust the speed of the playback of an audio while playing in Objective C for the iPhone/iPod touch?
Also would be interesting if playing a file backwards would be possible.
Thanks
Tom
AVAudioPlayer doesn't give you speed control, but it does let you set the position, so you could do a poor man's speed up/reverse the same way QuickTime Player does: by jumping through the file and playing small snippets at normal speed.
Or you decompress the samples yourself with an offline AudioQueue and do whatever rate you want. That's what I do.
A cheesy way to do it is to tweak the sample rate when you send it to the playback engine (Audio Queue, Remote I/O Unit, OpenAL). For PCM -- and I'm not sure this would work for anything other than PCM (so you'd have to decompress an MP3 or AAC with Audio Converter Services first) -- you could speed up your audio by adjusting the AudioStreamBasicDescription like this:
audioStreamDesc.mSampleRate = audioStreamDesc.mSampleRate * 1.2;
Note that this also changes the pitch of your audio: not only is it faster, it's also higher pitched. The Mac has a system-supplied audio unit that allows you to change playback speed without changing pitch, but it seems to be absent on iPhone.
As of iOS 6 (and I believe 5) you can adjust playback rate within AVAudioPlayer; no extra code necessary:
player = [[AVAudioPlayer alloc] initWithContentsOfURL:
[NSURL fileURLWithPath:path] error:&err];
player.enableRate=YES;
player.rate = 0.5;
[player play];
Rate can range between .5 and 2.0, and can be adjusted during playback as long as enableRate is set to YES before playback starts.
Related
I want to record audio for 10 seconds and take a snap when I stop recording the audio using AVCamCaptureManager in Objective C.
I gone through
AVCaptureSession specify resolution and quality of captured images obj-c iphone app
and implemented the same.
I am also using AVAudioSession to record audio when I start AVCamCaptureManager to take snap but it do not record audio its because AVCamCaptureManager also use the same audio device resource to record audio.
How can I do this? Please help..
I have edited my videos in final cut pro and used their export to http live streaming, which includes an audio, cell low and hi video, wifi low and hi, .m3u8 and index files. I have put all the files onto my web server and am using this to call the videos
-(IBAction)introVideo:(id)sender
{
NSLog(#"intro button pressed");
NSString *url = #"http://www.andalee.com/iPhoneVideos/intro/Intro.m3u8";
MPMoviePlayerViewController* moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
}
(Side note: how should this be released?)
Here is the Index.m3u8
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=225416,CODECS="mp4a.40.2, avc1.42e015"
Intro%20-%20Cellular%20Low.segments/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=480386,CODECS="mp4a.40.2, avc1.42e015"
Intro%20-%20Cellular%20High.segments/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=751434,CODECS="mp4a.40.2, avc1.42e01e"
Intro%20-%20Wi-Fi%20Low.segments/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1250210,CODECS="mp4a.40.2, avc1.4d401e"
Intro%20-%20Wi-Fi%20High.segments/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2545049,CODECS="mp4a.40.2, avc1.4d401e"
Intro%20-%20Broadband%20Low.segments/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=5056100,CODECS="mp4a.40.2, avc1.4d401f"
Intro%20-%20Broadband%20High.segments/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=33290,CODECS="mp4a.40.2"
Intro%20-%20Audio%20for%20HTTP%20Live%20Streaming.segments/prog_index.m3u8
When I test my app I initially get video and sound, but after 30 seconds I lose video while the audio continues to play. Any ideas what would be causing this?
This could simply be caused by a low bandwidth condition, which will trigger a bitrate change (in this case to the audio only version). If you try it in the emulator with a local server it might work correctly.
Most likely the file which is used next after the intro has wrong codec or the path is not right. Make sure all of the paths in Intro.m3u8 are correct and reachable from outside.
I am using AVPlayer for playing song from iPod Library. There are very limited methods in AVPlayer compare to AVAudioPlayer.
When I play song using AVPlayer in iPhone, the actual sound is very low compare to the song played in iPod Library.
My code goes as below:
AVPlayer *avPlayer = [[AVPlayer alloc] initWithURL:songURL];
[avPlayer play];
How can I amplify sound or increase volume while playing with AVPlayer??
Edit:
I had also gone through this question and tried the apple's link but there is no significant difference in sound. I tried passing volume in float as 0.8, 1.0, 2.0, 10.0, 100.0. But when i pass higher values then disturbance increases... and Volume does not increase.
What are the other ways to increase sound with AVPlayer??
Check out this link.
You cannot set volume greater than 1.0 for AVPlayer. If you increase volume to a value more than 1.0 then the distortion of voice and disturbance will increase.
But you need to check whats the output source of the player. Default is microphone, so try setting it to loudspeaker to get louder output.
Please refer below link for that.
How to record and play sound in iPhone app?
How to increase volume of sound recorded using AVAudioRecorder
Hope this help you.
HI all
i am playing a video(.mp4 format) without sound (i mean it doesn't have sound it is a mute video ) and in the background i am playing an audio file (.mp3 format) when i play my code through simulator it works fine as i want like when i tap on the video it is just mute but behind i am playing the audio so for user it seems that video has this sound but when i installed my code in device and play video than it doesn't work like so it play video but without sound than how can i play an audio and a video together in the above format ?
actually we are not just playing a single video or audio file it just comes from an array by choosing randomly and same for the audio file so we cann't do this i think so any other idea for it ??
Should we use another format for audio aur video for doing this thing ??
thanks for the help
Balraj verma
The problem is that the default Audio Session does not allow audio mixing.
In the Reference Library (Working with Movie Players) they say you should use a mixable category configuration for your audio session, for example the Ambient category. In the Application Delegate:
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *setCategoryError = nil;
[audioSession setCategory:AVAudioSessionCategoryAmbient error: &setCategoryError];
Apple's documentation states that some audio formats are not suited to be played back simultaneously because of hardware restrictions. See Playing Multiple Sounds Simultaneously for more details.
A solution for you would be to use PCM encoded audio which should allow simultaneous playback.
I would like to add that I managed to play two mp3 audio files at the same time on 3G and 3GS iPhones. Which shouldn't be possible according to documentation but worked for me.
You can rather use the an instance of AvAudioPlayer in a new thread. Use the following link to see how does this work
http://www.mobileorchard.com/easy-audio-playback-with-avaudioplayer/
create an instance of MPMoviePlayer to start playback of videos.
Hope this will work.
You should combine the audio and video using some video editing software like iMovie or Windows Movie Maker. Using the software to "composite" audio and video together is not a good idea and adds additional overhead, synchronization issues, etc.
As far as I know, you can't play AVAudioPlayer and MPMoviePlayer at the same time.
If i play my sounds on the iPhone on max ringer volume it plays fine But when i reduce it to some extend ma AudioToolbox sounds are playing at the same volume But my AVAudioPlayer sounds are playing fine. Is there any way to decrease the volume of sounds played by AudioToolbox...
From: iPhone Application Programming Guide
The AudioServicesPlaySystemSound function lets you very simply play short sound files. The simplicity carries with it a few restrictions. Your sound files must be:
Shorter than 30 seconds in duration
In linear PCM or IMA4 (IMA/ADPCM)
format Packaged in a .caf, .aif, or
.wav file
In addition, when you use the AudioServicesPlaySystemSound function:
Sounds play at the current system
audio level, with no level control
available
Sounds play immediately
Looping and stereo positioning are
unavailable