I'm using MPMusicPlayerController to play a list of mp3 in my app.
The only problem is when I set the volume level, according with app configuration, appears a Volume Level pop up.
I tried to find any property in order to hide it, but I didn't find.
The code I'm using is:
if (audioPlayer)
if ([audioPlayer isPlaying])
[audioPlayer stop];
self.musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(handlePlaybackStateChanged:) name:MPMusicPlayerControllerPlaybackStateDidChangeNotification object:self.musicPlayer];
[self.musicPlayer beginGeneratingPlaybackNotifications];
[self.musicPlayer setAccessibilityElementsHidden:YES];
self.musicPlayer.volume = volume;
[self.musicPlayer setQueueWithItemCollection:mediaItemCollection];
self.musicPlayer.repeatMode = MPMusicRepeatModeAll;
[self.musicPlayer play];
My question is, Any way to avoid this pop up?
Thanks.
I found a workaround for this problem in other post
But, there is not a direct way to perform that without using MPVolumeView "invisible"?
Sorry :)
Related
I am trying to use ScriptingBridge to write a small iTunes controller. The problem is to find an efficient way of getting notifyed whenever any changes occur. My first approch was to poll the input in a loop and just keep checking for differences. But I think there must be a more efficient way of getting notifyed about input!
Thanks in advance!
iTunes sends out a notification when something changes so just register for it in your init method of AppDelegate. Here's an example...
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:#selector(receivediTunesNotification:) name:#"com.apple.iTunes.playerInfo" object:nil];
The actual notifcation object in your method "receivediTunesNotification:" will contain information about the changes.
I am having an issue in my iPhone app with sound.
I have a UISlider object that I use to adjust the sound volume.
When it appears I use code based on the following line, to set the initial value of the slider:
AudioSessionGetProperty ('chov',&dataSize,&volume);
and that works fine. Then I would like the slider to move accordingly when I activate the hardware sound volume buttons of the device.
But this part based on this kind of code:
AudioSessionPropertyID volumeChangeID=kAudioSessionProperty_CurrentHardwareOutputVolume;
AudioSessionAddPropertyListener(volumeChangeID,handleSoundVolume,self);
does not work so well.
What I can see is that the callback function:handleSoundVolume is only called when some sound is playing and not otherwise.
On the other hand the value provided by AudioSessionGetProperty is always correct independently of sound playing or not.
Why is that?
I thought AudioSessionGetProperty and AudioSessionAddPropertyListener were working "together", but it does not seem so.
Looking at the default Music app on iPod touch, it seems that what I want to do is quite possible.
Thanks for any piece of information.
I have seen the same problem, the callback did not work at all for me.
The best solution is to add an observer to the NSNotificationCenter, for property AVSystemController_SystemVolumeDidChangeNotification.
NSNotificationCenter * center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:#selector(volumeChanged:)
name:#"AVSystemController_SystemVolumeDidChangeNotification"
object:nil];
and you have the method
- (void)volumeChanged:(NSNotification*)notification
{
float volume = [[[notification userInfo]
objectForKey:#"AVSystemController_AudioVolumeNotificationParameter"]
floatValue];
}
by the way I recommend instead of using 'chov' you should use the constant
kAudioSessionProperty_CurrentHardwareOutputVolume
i came across a strange problem, when i add pictures to an past event from web-end,everything is ok,however when i did that from my own iOS app, there's no exception,i just can't see the newly added image.Can't we add photos to the past events from mobile client? Anyone knows that.
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:image,#"source", nil];
[facebookDelegate requestWithGraphPath:[NSString stringWithFormat:#"%#/photos",self.eventID] andParams:params andHttpMethod:#"POST" andDelegate:self];
There's no errors,but i just can't see the uploaded pictures.
And another question, how to set event's profile picture with graph api? I used the following code:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:image,#"picture", nil];
[facebookDelegate requestWithGraphPath:self.eventID andParams:params andHttpMethod:#"POST" andDelegate:self];
It also doesn't work.What's more, i want to konw if we can upload image from web,so we just offer the picture link to facebook ?
thanks.
i think you can try the first one now. It work now
In most systems, the default behaviour for "open a new window" is that it appears at the front. This doesn't happen in Cocoa, and I'm trying to find the "correct" way to make this standard behaviour. Most things I've tried only work for a maximum of one window.
I need to open multiple windows on startup:
(N x NSDocuments (one window each)
1 x simple NSWindowController that opens a NIB file.
Things that DON'T work:
Iterate across all the NSDocuments I want to open, and open them.
What happens? ... only the "last" one that call open on comes to the front - the rest are hidden, invisible, nowhere on the screen, until you fast-switch or use the Window menu to find them.
Code:
...documents is an array of NSPersistentDocument's, loaded from CoreData...
[NSDocumentController sharedDocumentController];
[controller openDocumentWithContentsOfURL:[documents objectAtIndex:0] display:YES error:&error];
Manually invoking "makeKeyAndOrderFront" on each window, after it's opened
What happens? nothing different. But the only way I can find to get the NSWindow instance is so horribly hacky it seems totally wrong (but is mentioend in several blogs and mailing list posts)
Code:
[NSDocumentController sharedDocumentController];
NSDocument* openedDocument = [controller openDocumentWithContentsOfURL:[documents objectAtIndex:0] display:YES error:&error];
[[[[openedDocument windowControllers] objectAtIndex:0] window] makeKeyAndOrderFront:nil];
...I know I'm doing this wrong, but I can't find out why/what to do differently :(.
Something that works, usually, but not always:
As above, but just use "showWindow" instead (I took this from the NSDocument guide).
Bizarrely, this sometimes works ... even though it's the exact code that Apple claims they're calling internally. If they're calling it internally, why does it behave different if I re-invoke it after they've already done so?
[[[openedDocument windowControllers] objectAtIndex:0] showWindow:self];
You can just open all the documents without displaying and then tell the documents to show their windows:
NSArray* docs = [NSArray arrayWithObjects:#"doc1.rtf", #"doc2.rtf",#"doc3.rtf",#"doc4.rtf",nil];
for(NSString* doc in docs)
{
NSURL* url = [NSURL fileURLWithPath:[[NSHomeDirectory() stringByAppendingPathComponent:#"Documents"] stringByAppendingPathComponent:doc]];
NSError* err;
[[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:url display:NO error:&err];
}
[[[NSDocumentController sharedDocumentController] documents] makeObjectsPerformSelector:#selector(showWindows)];
Won't this work?
For 10.6 or greater
[[NSRunningApplication currentApplication] activateWithOptions:(NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps)];
This often has something to do with the app itself: your other windows are behind other apps (in particular, behind Xcode!), and would have appeared with a Hide Others command.
The solution to that problem would be that after you send showWindow to all of your windows (making sure you do the key one last), you tell the app to come forward, relative to other apps.
NSApp.activateIgnoringOtherApps(true) // Swift
or
[NSApp activateIgnoringOtherApps:YES]; // Objective-C
See also: How to bring NSWindow to front and to the current Space?
I have a MAAttachedWindow that shows itself when a status bar item is clicked. I need to have it close when its clicked outside of. I found some other directions that say to set it as a delegate and use - (void)windowDidResignKey:(NSNotification *)notification to detect when the user exits the window. I've tried it many times but can't seem to get it working which is probably because I didn't correctly set the delegate. Whats the best way to set the delegate so it will respond to the notification? The code is available here.
Thanks in advance
I found out to get the notification you have to register for it.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(windowDidResignKey:)
name:NSWindowDidResignKeyNotification
object:self];