avfoundation

IOS can I use AVAudioPlayer on the appDelegate?

早过忘川 提交于 2019-12-06 01:44:01
I have a TabBarController with two tabs and I want to play music on both tabs. Right now I have my code on the main appDelegate NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"My Song" ofType:@"m4a"]]; // My Song.m4a NSError *error; self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; if (error) { NSLog(@"Error in audioPlayer: %@", [error localizedDescription]); } else { //audioPlayer.delegate = self; [audioPlayer prepareToPlay]; } but I'm getting the error Program received signal: "SIGABRT" on UIApplicationMain Is there a better way

How to stop/cancel playSoundFileNamed in Swift?

 ̄綄美尐妖づ 提交于 2019-12-06 01:03:34
I'm trying to make a button, which is when pushed - the sound is played, and when pushed again - the sound would stop. I'm using playSoundFileNamed: runAction: withKey: and removeActionForKey , but it doesn't work. The other question I have is if there is a way not only to stop the sound, but also to pause it (so that it will start from the same part it was paused, NOT from the beginning). I've seen a similar topic at stack overflow, but yet didn't find an answer on my question yet. Thank you in advance. import SpriteKit import AVFoundation var firesoundon = false private var

How to convert code AVFoundation objective c to Swift?

对着背影说爱祢 提交于 2019-12-06 00:37:52
问题 I am using AVFoundation in swift for take pictures but I can't convert any func lines of code from objective c to Swift. My func code is: - (void) capImage { //method to capture image from AVCaptureSession video feed AVCaptureConnection *videoConnection = nil; for (AVCaptureConnection *connection in stillImageOutput.connections) { for (AVCaptureInputPort *port in [connection inputPorts]) { if ([[port mediaType] isEqual:AVMediaTypeVideo] ) { videoConnection = connection; break; } } if

AVfoundation Reverse Video

僤鯓⒐⒋嵵緔 提交于 2019-12-06 00:05:14
问题 I tried to make video in reverse. While playing asset in AVPlayer i set the rate = -1 to make it work in reverse format. But how to export that video? I looked into docs. read about avassetwrite, sambuffers , compositions but didn't find any way to do this. Below links are refered by me http://www.raywenderlich.com/13418/how-to-play-record-edit-videos-in-ios Reverse video demo - https://github.com/mikaelhellqvist/ReverseClip Above example to no longer works in IOS 8. and even it is not

What are the BCP-47 voice codes available for iOS 7 AVSpeechSynthesisVoice?

旧时模样 提交于 2019-12-05 23:18:50
问题 Today I'm very exited about the speech synthesis function is available in iOS7. I want to select the male voice(default in OSX, called alex). I don't know what's the BCP-47 code for him, and BTW how to get the full list of all voice code 回答1: Here's how to get the BCP-47 codes of the available voices: for (AVSpeechSynthesisVoice *voice in [AVSpeechSynthesisVoice speechVoices]) { NSLog(@"%@", voice.language); } Alex's locale is "English - United States" (en-US), as you can see in the Dictation

How do I loop a video with AVFoundation without unwanted pauses at the end?

故事扮演 提交于 2019-12-05 22:32:03
I am trying to play a video clip that loops indefinitely. I am doing this the way Apple recommends; by setting up a notification that gets triggered by AVPlayerItemDidPlayToEndTimeNotification: @property(nonatomic) AVPlayer *videoPlayer; @property(nonatomic) AVPlayerItem *videoPlayerItem; -(void)loadVideo { NSURL *url = [[NSBundle mainBundle] URLForResource:filename withExtension:extension]; AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil]; NSString *tracksKey = @"tracks"; [asset loadValuesAsynchronouslyForKeys:@[tracksKey] completionHandler: ^{ dispatch_async(dispatch_get_main

AVCaptureDevice doesnt find any device

筅森魡賤 提交于 2019-12-05 22:00:56
This line of code is the problem I got today (macOS app): NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; After I update Xcode, the system is alway got me empty devices array. The thing is, the old projects(created before the update) work as expected. What's going on here...? Does anyone has the same problem? ------------UPDATE------------ I found this not just happened to my mac, also on the company's. And it does affect my work. I think I found the answer... Target Settings / Capabilities / App sandbox / Hardware This problem only happens on the Mac OS 10.13, Mac

How to add multiple CALayer to a video file using AVMutableComposition and CALayers on iOS

青春壹個敷衍的年華 提交于 2019-12-05 21:51:43
I want to add multiple CALayer one after another by time sequence.I can add one layer to video file using this link Here . Now my question is that how can i add multiple CALayer to video file. Thanks in advance.. Most straightforward way is to bundle several layers into single layers. You will have to add instructions to add it at some point and remove when not needed. Something like this: CABasicAnimation *fadeAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; fadeAnimation.fromValue = [NSNumber numberWithFloat:(float)!fadeIsIn]; fadeAnimation.toValue = [NSNumber numberWithFloat:

Swift : take photo from AVFoundation

╄→尐↘猪︶ㄣ 提交于 2019-12-05 21:23:55
I want to translate this func from obj c to swift, buti can't translate a part of the code. Could someone explain me how to take photo from AVFondation or help me to translate this function ? - (void) capImage { //method to capture image from AVCaptureSession video feed AVCaptureConnection *videoConnection = nil; for (AVCaptureConnection *connection in stillImageOutput.connections) { for (AVCaptureInputPort *port in [connection inputPorts]) { if ([[port mediaType] isEqual:AVMediaTypeVideo] ) { videoConnection = connection; break; } } if (videoConnection) { break; } } NSLog(@"about to request a

How do I make AVCaptureSession and AVPlayer respect AVAudioSessionCategoryAmbient?

删除回忆录丶 提交于 2019-12-05 21:08:02
I'm making an app that records ( AVCaptureSession ) and plays ( AVPlayerLayer ) video. I'd like to be able to do this without pausing background audio from other apps and I'd like the playback to respect the mute switch. In the AppDelegate I have set AVAudioSessionCategoryAmbient , according to the docs this should: The category for an app in which sound playback is nonprimary—that is, your app can be used successfully with the sound turned off. This category is also appropriate for “play along” style apps, such as a virtual piano that a user plays while the Music app is playing. When you use