Cocoa Audio / QTKit [play/pause toggle button] (error) - objective-c

I'm using this example to make a simple audio player which involves using the QTKit framework, although I can't figure figure out how to make a 'toggle' play/pause button instead of two separate buttons.
I've tried using the following code and it doesn't work, the error message is: (Statement requires expression of scalar type ('void' invalid)
- (IBAction)togglePlayback:(id)sender;
{
if([self play])
{
[self stop];
}
else
{
[self play];
}
}
Any help would be appreciated, or if there is a better way to have an audio track play when the application opens with a toggle 'play/pause' switch.

Well it looks like [self play] doesn't return YES or NO. You could go for an instance variable (e.g. isPlaying) which you are toggling.
Btw - If you are targeting 10.7 lion or iOS you could go for AVFoundation/AVAudioPlayer which is a bit newer API.

Related

how to turn off the Camera Light while taking snap programmatically?

I'm developing one app in which i want to capture an image at run time.
It has to work for both MAC PRO & Mac mini (If web cam is connected). When Camera takes picture small light will come at the time of taking snap, that should not come. Its not regarding the flash.
code snippet:
- (void)captureOutput:(QTCaptureOutput *)captureOutput didOutputVideoFrame:(CVImageBufferRef)videoFrame withSampleBuffer:(QTSampleBuffer *)sampleBuffer fromConnection:(QTCaptureConnection *)connection
{
// If we already have an image we should use that instead
if ( currentImage ) return;
// Retain the videoFrame so it won't disappear
// don't forget to release!
CVBufferRetain(videoFrame);
// The Apple docs state that this action must be synchronized
// as this method will be run on another thread
#synchronized (self) {
currentImage = videoFrame;
}
// As stated above, this method will be called on another thread, so
// we perform the selector that handles the image on the main thread
[self performSelectorOnMainThread:#selector(saveImage) withObject:nil waitUntilDone:NO];
}
To capture picture i'm using the above method. Thanks in advance
According to this article, several older MacBooks' camera LEDs could be circumvented by tying into the circuit board logic directly.
To my knowledge, there is no longer this security loophole, nor is there an API available in Objective-C to disable the camera LED.

Terminating an application when closing the window

I'm a little bit new to Objective-c with xCode, and I would like to know something. Is there a way to terminate an application when the red circle in the left of the window is clicked? Like on the calculator.
Yes you can do with Mac OSX applications.
You need to implement this method in your AppDelegate class
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender{
return YES;
}
If you want terminate the app when closing the window. Please implement the following appdelegate method.
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
{
return YES;
}
If you want do not terminate your app, just set the return "NO".
I hope that your problem will be resolved with this solution.

Why won't my custom view become First-Responder, iOS?

I am following the book, iOS Programming Big Nerd Ranch Guide, and I have come to a lesson where I am to create a custom view, HypnosisView. Now, I am suppose to have this view change it's color on shake, but it says I am suppose to make it the First-Responder.
I used,
- (BOOL)canBecomeFirstResponder
{
return YES;
}
and
BOOL success = [view becomeFirstResponder];
if (success) {
NSLog(#"HypnosisView became the first responder"):
} else {
NSLog(#"Could not become first responder");
}
However, whenever I run my app, it always says that it could not become the first responder.
Any help would be appreciated.
UPDATE
I forgot to mention I get this output message.
Application windows are expected to have a root view controller at the end of application launch
Alright. I figured it out. I needed to put the delegate method
- (BOOL)canBecomeFirstResponder
{
return YES;
}
In the CustomView.m file, not my App Delegate file. Easy fix.

Fullscreen app in OS X with multiple windows?

I want to make a fullscreen app that shows the background of the new space, in addition to having normal window behavior. Basically, when the user goes full screen, I want every NSWindow in the app to stay the same size, stay in the same position of the screen, but move to the new space. Is this possible? If so, where is the documentation for that kind of behavior?
EDIT: I know this is now quite old, but I have just discovered customWindowsToEnterFullScreenForWindow. I have used it to solve the problem. The code is below, just incase anyone else is interested in doing this too.
- (NSArray*) customWindowsToEnterFullScreenForWindow:(NSWindow*)window {
if ([window isEqualTo:self.window]) {
return [NSArray arrayWithObjects:window, otherwindow, nil];
}
return nil;
}
- (NSArray*) customWindowsToExitFullScreenForWindow:(NSWindow*)window {
if ([window isEqualTo:self.window]) {
return [NSArray arrayWithObjects:window, otherwindow, nil];
}
return nil;
}
These are NSWindowDelegate methods though, so be sure to set the window's delegate. Otherwise, it may cause some confusion.
An app can only be on one space at a time. This is a hard limitation. You should file a bug if you want to be able to manage multiple windows on multiple spaces in fullscreen.

Get ADInterstitialAd to load more often on iPad: possible?

I'm testing my iAd on my iPad, and I can't seem to get my ADInterstitialAd to load very often.
It does run occasionally but most of the time the first method below is called
- (void)interstitialAd:(ADInterstitialAd *)interstitialAd didFailWithError:(NSError*)error{
NSLog(#"Ad Failed");
//[self cycleInterstitial];
}
However when I try to reload it upon failing.(see below method) It just fails over and over. I dont see why apple would let it just fail in a testing environment. I have read that the fill rate can be low, but it seems really low just for a test iPad app.
- (void)cycleInterstitial{
// Clean up the old interstitial...
interstitial.delegate = nil;
[interstitial release];
// and create a new interstitial. We set the delegate so that we can be notified of when
interstitial = [[ADInterstitialAd alloc] init];
interstitial.delegate = self;
}
Can anyone please advise? Thanks!
No, sorry. Apple is solely responsible for the fill rate of iAds, including interstitial iAds for iPad. As developers and users, we do not have any direct control over this.