Checking if iTunes is shuffling is not working - objective-c

I'm developing a Mac App and I need to check if Itunes (11.0) is shuffling my music so, to check that, I'm using iTunes.h and the following code:
if([iTunes.currentPlaylist shuffle]){
NSLog(#"yes");
}else{
NSLog(#"no");
}
Even though I have my iTunes shuffling, it always outputs "no".
Any ideas why is this happening or am I checking it the wrong way?

This I know: in iTunes 11 some things changed. One of them is that the "shuffle"-option is playlist-independent...

Good luck with that.
I reported a bug about a month ago, like tons of other developers.
Didn't hear anything, and probably won't.
Like DigiMonk wrote, it a change in iTunes 11, but they don't update their API.

A long way around for the time being might be to listen for NSDistributedNotifications and check whether the attributes for the currently playing track match the previous or next one. It's not the cleanest solution, but it should work if what's being shuffled is an album or artist. Just check whether the track numbers go in sequence, or if the artist name is the same, etc.

Related

WatchKit: Video Duration

Is there a way to determine the duration of a video currently set to WKInterfaceInlineMovie? I need to implement a circular progress bar displaying a current progress.
I have a URL of the file initially downloaded from network. It plays well, but I haven't found any way to determine its length (actually, nor questions asking that which is strange).
Of course, I can ask the backend server to send this info, but I'd like to avoid such complications if possible.
OK, it seems I overcame the WKInterfaceInlineMovie API limitation by the help of AVFoundation and CoreMedia.
I create AVAsset object using a movie URL from a shared folder (AVAsset(url:)). Then I get CMTime duration from the AVAsset's duration property (which is a CMTime object).
Actually, I was very surprised to find out that it works. I'm still testing it, because it's too good to be true and I'm expecting to run across some pitfalls. I'll update the answer if anything else's found.

Issues/Questions regarding NSUserDefaults

OK, I admit NSUserDefaults, being a Mac-specific thing (and me being a Mac programmer for the last couple of years), is one of the things I haven't delved into that much... so here are some issues/questions I've come across :
I understand that NSUserDefaults is basically an NSMutableDictionary written as a .plist.
My questions :
Given that I'm running OS X 10.7 (Lion) and having enabled Sandbox, where is my app's .plist file? (I've search in both ~/Library/Preferences/com.example.myapp.plist and ~/Library/Containers/com.example.myapp/Data/Library/Preferences/com.example.myapp.plist but none of these seems valid
I understand that this .plist file is created the first time the app launches, correct?
registerDefaults: is to be used at application launch (e.g. in awakeFromNib) and provide a Dictionary of default values that are immediately stored in the .plist file, and changed only if a different value is set at some point, correct?
When we're setting a specific Key-Value pair, is that pair automatically and immediately saved to the .plist file? And if so, why/when should we use synchronize? (Is using it every single time some value is set an overkill, or should it be reserved for special cases?)
Sidenote : I hope nobody complains about my use of the osx tag. However, I'm really tired of seeing Cocoa Touch / iOS related answers to my (mostly) OSX-related questions. So, here you are... :-)
EDIT : For some really helpful insight on the subject, please have a look at the accepted answer as well as the comments below it.
Answer 1. The home directory is hidden in Lion, so you are not able to enter the path(Without seeing the folder you can not enter inside the folder from Finder). You can use Path Finder to move around your hidden directories.
Answer 2. Not always. There can be multiple plists in a single application. Few gets created at first launch, few at some specific action. Actually it depends when the plist file are created and how to use it.
Answer 3. registerDefaults: registers default values are when the user has not set other values to that property. It will not override whatever the user has stored when the app is opened later. You can use it in anywhere, but as stated it will be used once.
Answer 4. For Mac OSX application there is no performance and overkill issues, however for iOS it has. It is always better to use [[NSUserDefaults standardUserDefaults] synchronize];

Moving a Window to a New Space in Mission Control

I would like to write a small utility that moves a window from one space to another in OS X Lion. I don't care if the utility is written in AppleScript or Objective-C. What I can't seem to figure out is given a window, how can I move it to a different space. I've seen lots of helpful information in this thread, but nothing about how to actually move the window. If anybody has any thoughts or ideas, I'd appreciate hearing them. Thanks.
If you are using objective-c calls, then moving between spaces in 10.7 is actually the same as 10.6 except for one issue. Space ID's were index based in 10.6, but based on something else (not quite a GUID) in 10.7.
If you have a window already in the correct space, the solutions in this question will work (I'm using it in csshX). You can get the space ID with CGSGetWindowWorkspace, and then set it on another window using CGSMoveWorkspaceWindowList.
Now if you don't have the space id - e.g. you just want to move the window to the 2nd space - then I'm as stumped as you are. I'm looking for the linkage between the space id and the index number. (Will update this answer if I find it)
Finally, you mention the App Store in the comment above - this will not be suitable since the CGS* calls use undocumented private frameworks which will get you rejected.
You will need to use a custom library, which can be found here http://macscripter.net/viewtopic.php?id=23453, however I'm not sure what kind of support it has in lion.

Make a video from an NSArray of NSImages

I know this has been asked before, but the only answers I have found use UIImages. I need to make a 25 fps video from an NSArray of NSImages in Objective-C. Could somebody give me a link to the documentation dealing with this (if there is any), or tell me how I can do it?
NOTE: I will also need to know which frameworks to use if there is no documentation on this. And, before you ask, I have done lots of searches for the documentation.
You can do this with QTKit by creating a movie and adding images as frames. See the "Creating a Single Frame-Grabbing Application" section. Step 13 specifically demonstrates how to add an image (and have it last a specific duration in the movie ... should probably last more than a single frame for, say, stop-motion stuff).

Does Apple's Game Center check the app version is up to date before match making? If not, how should I do this?

I have a game for the iPhone that I would like to introduce matchmaking for. However, thinking in advance, I don't want to make updates and have players that are not up to date matchmaking with other players.
Please tell me Apple's Game Center is smart enough, but if not, how should I prepare?
You can use playerGroup to make sure that you are not getting players matched that have different app versions. Just convert your version to a unique integer (e.g. 1.2 becomes 102) and put it into the playerGroup property of your GKMatchRequest.
Then, only games with the same playerGroup (=version) get matched to each other.
Note that you don't really make sure that older versions are not matched among each other (which would be bad policy anyway) but you can at least prevent games between different versions.
For more info, see Advanced Matchmaking Topics in http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/GameKit_Guide/Matchmaking/Matchmaking.html
Edit: Apple has recently added Multiplayer Compatibility in Game Center. Click on your app and set the versions this game is compatible with. This also works across game bundles now with game center groups.
I don't believe Apple will do this for you so the best method I've come across is to keep a tiny txt file on your own server that you can check against.
Like so:
NSString *versionString = [NSString stringWithContentsOfURL:[NSURL URLWithString:#"http://www.myurl.com/latestversion.txt"] encoding:NSUTF8StringEncoding error:&error];
if(GAME_VERSION != [versionString floatValue])
{
//the latest version did not match the game version
}