Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // AppDelegate.m
- // NowPlaying
- //
- // Created by thislooksfun on 7/14/14.
- // Copyright (c) 2014 thislooksfun. All rights reserved.
- //
- #import "AppDelegate.h"
- #import "iTunes.h"
- @implementation AppDelegate
- @synthesize statusBar = _statusBar;
- @synthesize scrollingText;
- @synthesize currentData;
- - (id) init
- {
- self = [super init];
- if (!self) return nil;
- NSDistributedNotificationCenter *dnc = [NSDistributedNotificationCenter defaultCenter];
- [dnc addObserver:self selector:@selector(onItunesChange:) name:@"com.apple.iTunes.playerInfo" object:nil];
- self.iTunes = [SBApplication applicationWithBundleIdentifier:@"com.apple.iTunes"];
- return self;
- }
- - (void) awakeFromNib
- {
- self.statusBar = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
- self.statusBar.menu = self.statusMenu;
- self.statusBar.highlightMode = YES;
- [self.scrollingText setText:@"Hello world!"];
- [self.scrollingText setSpeed:0.03];
- self.statusBar.view = self.scrollingText; //Here
- [self onItunesChange:nil];
- }
- - (void) onItunesChange:(NSNotification *)notification
- {
- iTunesEPlS state = [self.iTunes playerState];
- switch (state) {
- case iTunesEPlSStopped: {
- currentData = nil;
- //[self.scrollingText setText:@"No song playing"];
- //[self.scrollingText setSpeed:0.03];
- self.statusBar.view = self.scrollingText;
- } break;
- default: {
- [self setSong];
- } break;
- }
- }
- - (void) setSong
- {
- NSString *str = @"";
- iTunesTrack *track = [self.iTunes currentTrack];
- if ([track podcast]) {
- str = [str stringByAppendingString:@"[Podcast] "];
- } else if ([[track kind] isEqualToString:@"Internet audio stream"]) {
- str = [str stringByAppendingString:@"[Radio] "];
- } else {
- str = [str stringByAppendingString:@"[Song] "];
- }
- NSString *title = [self.iTunes currentStreamTitle];
- NSString *trName = [track name];
- NSString *trArtist = [track artist];
- NSString *trAlbum = [track album];
- if (title != nil) {
- str = [str stringByAppendingString:title];
- }
- if (trName != nil && ![trName isEqualToString:@""]) {
- if ([str length] > 0) {
- str = [str stringByAppendingString:@" "];
- }
- str = [str stringByAppendingString:trName];
- }
- if (trArtist != nil && ![trArtist isEqualToString:@""]) {
- if ([str length] > 0) {
- str = [str stringByAppendingString:@" — "];
- }
- str = [str stringByAppendingString:trArtist];
- }
- if (trAlbum != nil && ![trAlbum isEqualToString:@""]) {
- if ([str length] > 0) {
- str = [str stringByAppendingString:@" — "];
- }
- str = [str stringByAppendingString:trAlbum];
- }
- return;
- if (![str isEqualToString:currentData]) {
- [self.scrollingText setText:str];
- [self.scrollingText setSpeed:0.03];
- self.statusBar.view = self.scrollingText;
- currentData = str;
- }
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment