GPUImageMovieWriter starting new recording - ios

Can i reuse an existing GPUImageMovieWriter (after calling finishRecording) or is there a method to pause and resume the recording?
I get error if i call startRecoding after a finishRecording.
Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: '*** -[AVAssetWriter addInput:] Cannot call method when status is 2'

You can't call startRecording() on the same movieWriter instance after calling finishRecording().
finishRecording() writes the completion block for the video into file, thus all subsequent frames added to the video file would be useless anyway. If what you want to achieve is to pause recording for a bit and append video at the end again after pausing, you should probably create a "pause" state where you don't record, but simply measure the amount of time paused, and then use an adjusted frame time for when you resume recording again.
Cheers!
Vijay

Related

Crash when first playing AVPlayer video and then recording audio in AudioKit

I'm having trouble using AudioKit in an iOS app that also use AVPlayer (for video). In my project I have one page with an AVPlayer video and a button that segues to a second page with a record and play button that uses AudioKit. If I don't start the video the AKNodeRecorder is working as expected, but if the video is played before recording the app crashes with the following message:
2018-04-13 13:18:10.576116+0200 AVPlayer_vs_AudioKit[1854:580107] [mcmx] 338: input bus 0 sample rate is 0
2018-04-13 13:18:10.576361+0200 AVPlayer_vs_AudioKit[1854:580107] [avae] AVAEInternal.h:103:_AVAE_CheckNoErr:
[AVAudioEngineGraph.mm:1839:InstallTapOnNode: (err = AUGraphParser::InitializeActiveNodesInInputChain(ThisGraph, *inputNode)): error -10875
2018-04-13 13:18:10.576691+0200 AVPlayer_vs_AudioKit[1854:580107] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'error -10875'
*** First throw call stack:
(0x183a3ed8c 0x182bf85ec 0x183a3ebf8 0x1893671a0 0x189383f58 0x189393410 0x18940c5e8 0x1893fc6e8 0x104e7db90 0x104d7d170 0x104d7d714 0x18d76e6c8 0x18d88f8a4 0x18d77477c 0x18d8aa1dc 0x18d7f1a48 0x18d7e68f8 0x18d7e5238 0x18dfc6c0c 0x18dfc91b8 0x18dfc2258 0x1839e7404 0x1839e6c2c 0x1839e479c 0x183904da8 0x1858e7020 0x18d8e578c 0x104d801a4 0x183395fc0)
libc++abi.dylib: terminating with uncaught exception of type NSException
I use AudioKit 4.2.3 from cocoapods on XCode 9.3
My project can be downloaded here: https://www.dropbox.com/s/gxek91sccit88zv/AVPlayer_vs_AudioKit.zip?dl=0
Configuring AudioKit's idea of an audio session early on to include recording fixes the problem, e.g. in application(didFinishLaunchingWithOptions:)
try! AKSettings.setSession(category: .playAndRecord, options: 0)

app crashing due to resource not loading properly randomly

basically Im making a game on Sprite Kit using Obj-C in XCode 5
whenever I tap the screen, I use an SKAction to play a sound file
[self runAction:[SKAction playSoundFileNamed:#"tap.caf" waitForCompletion:NO]];
Previously I used the mp3 file that i had of the same sound and the error kept popping up randomly after about more than 50 taps at least, sometimes more sometimes less, sometimes it doesn't even cause an error,
So i read the apple documentation and decided to convert to ima4 .caf extention.
I'm not sure if its made a difference, It happens much less often. I've got 2 more audio files that are played through SKActions and none of them have yet failed loading.
Any suggestions?
Debug console output below:
2014-07-05 16:14:15.716 GoUp[777:60b] *** Terminating app due to uncaught exception
'Failed to Load Resource', reason: 'Resource tap.caf can not be loaded'
*** First throw call stack:
(0x306d7fd3 0x3ae86ccf 0x306d7f15 0x32e09e55 0x32dc2b2d 0xf9331 0x32de69ab 0x32f28651
0x32f236eb 0x32ef88ed 0x32ef6f97 0x306a325b 0x306a272b 0x306a0f1f 0x3060bf0f 0x3060bcf3
0x35510663 0x32f5716d 0xfcd61 0x3b393ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Just to add, I tried to check if the file was faulty by setting a repeatforever waitforcomplete:YES SKAction playing the sound file, (i did wait for it to complete each time otherwise, it may have crashed due to significant number of actions). It ran without problem for at least 5 mins, until i decided to stop the app. Not sure if this confirms the file is not damaged
EDIT 2 : Just tried a different sound file and it happened again with a different file :(
I have no explanation about why that "crash" occurs,
but, you can easily solve this problem by declaring and loading your sounds into cash (to avoid to load it each time the sound is played) as follow:
In the .h
#property (strong, nonatomic) SKAction *aSound;
in the .m
Ignit it on the top:
self.aSound = [SKAction playSoundFileNamed:#"FileName.wav" waitForCompletion:NO];
En then call it each time you want to play the sound:
[self runAction:_aSound];
Also and for some reasons,
I advice you to convert all your Audios files into .Wav, which is uncompressed (allowing much more speed from the Processor that hasn't uncompressed the file before to read it)
It also dodge a lot of exceptions in C picked-up from the Breakpoint of Xcode.

Save data in ApplicationDidEnterBackground terminating due to background thread pause delay

My app currently downloads data from a web service. The data received is processed using background serial queues.
I also want to save the data to the file system when the user goes into background mode and use NSCoder to do this. Based on Apple's recommendation, I have included the save file logic in the ApplicationDidEnterBackground method of the app delegate.
However, I am having problems ensuring the data is not mutated before the save to file system is called because the background thread pause is not called immediately.
For example, a refresh of client data is kicked off and returns 2000+ records (simple data scheme). However, while this is running, the user presses the Home button and the App goes into the background and attempts to save the data to file system.
Within the block processing of the background thread, I have included logic to log when clients are added to the array, as well as included NSLog messages to tell me when the ApplicationDidEnterBackground method is called. Here are the relevant parts of the logging results:
2014-06-06 12:32:02.360 MyApp[629:190049] Added client
2014-06-06 12:32:02.365 MyApp[629:190049] Added client
2014-06-06 12:32:02.416 MyApp[629:189936] This is a call to applicationDidEnterBackground to save data to file
2014-06-06 12:32:02.371 MyApp[629:190049] Added client
. . . (Log continues with Added Client messages)
2014-06-06 12:32:03.952 MyApp[629:190049] Added client
2014-06-06 12:32:03.951 MyApp[629:189936] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x157c74f0> was mutated while being enumerated.'
*** First throw call stack:
(0x23df543b 0x3096ed1f 0x23df4ec1 0x24ab44e7 0x24ab4ad9 0x24ab32ed 0x24affb53 0x4f879 0x4f71b 0x2a257 0x2762021d 0x2761c51d 0x2a32ae27 0x2a3319f5 0x23dbd135 0x23dbc3f9 0x23dbaf53 0x23d077e1 0x23d075f3 0x2ae5a261 0x27412e3d 0x27e4b 0x30f07aaf)
libc++abi.dylib: terminating with uncaught exception of type NSException
2014-06-06 12:32:03.960 MyApp[629:190049] Added client
2014-06-06 12:32:08.025 MyApp[629:190049] Added client
2014-06-06 12:32:08.028 MyApp[629:190049] Added client
2014-06-06 12:32:08.030 MyApp[629:190049] Added client
As can be seen from the logs, the background thread block processing continues to process records even after ApplicationDidEnterBackground is called (and in fact, even after the exception is called), causing the file save to fail due to a mutated array.
Does anyone have any suggestions on how best to handle ensuring the save of file only occurs AFTER the background queue is paused? I would prefer not to cancel the thread processing if possible. Thanks in advance.
In case someone else has a similar problem...
I resolved this through adding the save to file methods to the same background queues I was processing each data set on rather than trying to cancel what was part way through.
This way, the save data did not kick in until the other data updates were complete, and the issue of saving to file while the array was being mutated has disappeared.

MPMoviePlayerController crashing and not playing movie

I am trying to play a movie using MPMoviePlayerController. When I call play method, i am getting following crash.
*** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <MPAVController 0x15786750> for the key path "currentItem" from <MPAVPlaylistManager 0x15787750> because it is not registered as an observer.'
*** First throw call stack:
(0x2f148ed3 0x391716c7 0x2f148e15 0x2fa7227f 0x2fa71ca7 0x30393977 0x3038d5ef 0x303889d5 0x3036a36b 0x3036c6bb 0x2f10ae79 0x2f07eb81 0x2fa463c5 0x2fa4acc7 0x303ef943 0x39672103 0x396720ef 0x396749a9 0x2f1135b9 0x2f111e85 0x2f07c541 0x2f07c323 0x33b10343 0x316957b5 0x3a719 0x3a6a0)
libc++abi.dylib: terminating with uncaught exception of type NSException
I am not sure whats happening, as I dont have setup any KVO observer for currentItem from MPAVPlaylistManager which is an internal class.
anybody else got this issue?
Your app is massing with MPMoviePlayerController instance that was created. I had the same issue a while back and As far as i can think of there can be two things 1. You are changing contentURL of the instance that you have created while playing a video 2.you are incorrectly releasing the instance of MPMoviePlayerController.
I resolved the issue, the problem was related to iOS7 (that is under NDA at the moment). AVPlayer behaviour is changed if the player is started from a secondary thread. the player object will be nil. fixed my issue.

Cocos2d: nasty exception with batched sprites

I can't quiet figure how to debug this. I have a CCScene running and when the scene is replaced I get the following error message.
The scene has a sprite batch node where the CCSpriteSubclass is added.
That's the cleanup method and below that you will find the assertion failure message:
-(void) cleanup
{
[[GameController sharedGameController].musicLayer removeMusicSourceForKey:backgroundMusicFileName];
[CCTextureCache purgeSharedTextureCache];
[CCSpriteFrameCache purgeSharedSpriteFrameCache];
[CCAnimationCache purgeSharedAnimationCache];
// [[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
[super cleanup];
}
The batch node is created as following in the initWithId:(int)sceneId method:
//Prepare sprites sheets for the rest of the game art
[frameCache addSpriteFramesWithFile:[NSString stringWithFormat:#"art%i-hd.plist", sceneId]];
sharedSpriteMainBatchNode = [CCSpriteBatchNode batchNodeWithFile:[NSString stringWithFormat:#"art%i-hd.png", sceneId]];
And then I add all CCSpriteSubclass objects.
That's the assertion failure message:
** Assertion failure in -[CCSpriteSubclass setTexture:], /Users/xxx/Desktop/xxx/xxx/libs/cocos2d/CCSprite.m:934
2012-12-03 12:54:33.335 RockTale[869:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'CCSprite: Batched sprites should use the same texture as the batchnode'
*** First throw call stack:
(0x338d28bf 0x303c61e5 0x338d27b9 0x311193b3 0x9ad43 0x9a2fb 0x4bca3 0x44ddf 0x38b07 0x503f7 0x94c03 0xbbeed 0xbcfe7 0x34fb7423 0x34fb7379 0x31b4cf93 0x36e52891 0x3389bf43 0x338a6553 0x338a64f5 0x338a5343 0x338284dd 0x338283a5 0x37f9afcd 0x3128b743 0x2edf 0x2ea0)
terminate called throwing an exception(lldb)
EDIT: Added a breakpoint to the setTexture method and here is what I "DON't" see :)
EDIT 2: I whish I could manage to retrieve the full stacktrace like in Java.. I have asked this in a different question and I was told I should add a global exception.. I still need to figure out how to retrieve the stacktrace..
From the text of your exception message it seems that you create sprites with spriteframes from different spritesheets.
I solved this problem in the same way as here. It was due to the fact that sprite frames where referred while the previous class was replacing the existing one and hence the previous class cleanup method was calling the purge frame cache which was consequently removing the yet unused sprite frames which where being loaded in memory by the newly created object.

Resources