Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 03-18-2011, 03:11 PM   #1 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 2
jp_semery is on a distinguished road
Default iPhone SDK: AVAudioRecorder will not record after calling [AVPlayer play]

Hi

I have a view controller that uses AVPlayer. this view controller can load a modal view controler where the user can record audio using AVAudioRecorder.

this is what happens:

if the user plays the composition in the fist controller with [AVPLayer play] the AVAudioRecorder will not record in the modal view controller. there are no errors but the current time returned by AVAudioRecorder is 0.0;

if the user dismisses the modal dialog and reloads it. AVAudioRecorder works fine.

this can be repeated over and over AVAudioRecorder does not work the first time it is invoked after a [AVPlayer play] call

I have been fighting with this for days and just have reorganized my code related to both AVPlayer and AVAudioRecorder and it's still acting weird.

Any help or pointer is much appreciated

Thanks in advance

Jean-Pierre
jp_semery is offline   Reply With Quote
Old 03-22-2012, 11:05 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2008
Location: London, UK
Posts: 250
mattjgalloway is on a distinguished road
Default

Did you ever figure this out? I'm seeing the same thing and it's really annoying me!
__________________
Beard Booth HD - See what you'd look like with a beard today!

My iPhone Apps
My iPhone Tutorials
mattjgalloway is offline   Reply With Quote
Old 05-03-2012, 09:41 AM   #3 (permalink)
New User
 
Join Date: Mar 2011
Posts: 2
ahayman is on a distinguished road
Default Found a Solution

Quote:
Originally Posted by mattjgalloway View Post
Did you ever figure this out? I'm seeing the same thing and it's really annoying me!

I've been having the same problem. I use AVPlayer to play compositions (previous recordings I've used AVAudioRecord for). However, I found that once I've used AVPlayer I could no longer use AVAudioRecorder. After some searching, I discovered that so long as AVPlayer is instantiated in memory and has been played at least once (which is usually what you do immediately after instantiating it) AVAudioRecorder will not record. However, once AVPlayer is dealloc'd, AVAudioRecorder is then free to record again. It appears that AVPlayer holds on to some kind of connection that AVAudioRecorder needs, and it's greedy...it won't let it go until you pry it from it's cold dead hands.

This is the solution I've found. Some people claim that instantiating AVPlayer takes too much time to keep breaking down and setting back up. However, this is not true. Instantiating AVPlayer is actually quite trivial. So also is instantiating AVPlayerItem. What *isn't* trivial is loading up AVAsset (or any of it's subclasses). You really only want to do that once. They key is to use this sequence:

1. Load up AVAsset (for example, if you're loading from a file, use AVURLAsset directly or add it to a AVMutableComposition and use that) and keep a reference to it. Don't let it go until you're done with it. Loading it is what takes all the time.
2. Once you're ready to play: instantiate AVPlayerItem with your asset, then AVPlayer with the AVPlayerItem and play it. Don't keep a reference to AVPlayerItem, AVPlayer will keep a reference to it and you can't reuse it with another player anyway.
3. Once it's done playing, *immediately destroy* AVPlayer...release it, set its var to nil, whatever you need to do. **
4. Now you can record. AVPlayer doesn't exist, so AVAudioRecorder is free to do its thing.
5. When you're ready to play again, re-instantiate AVPlayerItem with the asset you've already loaded & AVPlayer. Again, this is trivial. The asset has already been loaded so there shouldn't be a delay.

** Note that destroying AVPlayer may take more than just releasing it and setting its var to nil. Most likely, you've also added a periodic time observer to keep track of the play progress. When you do this, you receive back an opaque object you're supposed to hold on to. If you don't remove this item from the player AND release it/set it to nil, AVPlayer will not dealloc. It appears that Apple creates an intentional retain cycle you must break manually. So before you destroy AVPlayer you need to (example):

Code:
    [_player removeTimeObserver:_playerObserver];
    [_playerObserver release]; //Only if you're not using ARC
     _playerObserver = nil;

As a side note, you may also have set up NSNotifications (I use one to determine when the player has completed playing)...don't forget to remove those as well.
ahayman is offline   Reply With Quote
Reply

Bookmarks

Tags
avaudiorecorder, avplayer

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 405
18 members and 387 guests
Brandt, coolman, Domele, Droverson, Duncan C, fredidf, Free App Monster, givensur, iAppDeveloper, locombiano89, Mah6447, MasterX, Meoz, simplymuzik3, SLIC, stanny, stevenkik, Tomsky
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,646
Threads: 94,111
Posts: 402,864
Top Poster: BrianSlick (7,990)
Welcome to our newest member, locombiano89
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:56 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0