MPNowPlayingInfoCenter defaultCenter nie aktualizuje ani nie pobiera informacji
Pracuję nad aktualizacją MPNowPlayingInfoCenter i mam mały problem. Trochę się starałem do tego stopnia, że jestem w rozsypce. Oto Mój kod:
self.audioPlayer.allowsAirPlay = NO;
Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
if (playingInfoCenter) {
NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"series_placeholder"]];
[songInfo setObject:thePodcast.title forKey:MPMediaItemPropertyTitle];
[songInfo setObject:thePodcast.author forKey:MPMediaItemPropertyArtist];
[songInfo setObject:@"NCC" forKey:MPMediaItemPropertyAlbumTitle];
[songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
}
To nie działa, ja też próbowałem:
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:nil];
W celu uzyskania go, aby usunąć istniejące informacje z aplikacji iPod (lub cokolwiek może mieć tam informacje). Ponadto, aby zobaczyć, czy mogę dowiedzieć się o problemie, próbowałem pobrać bieżące informacje o uruchomieniu aplikacji:
NSDictionary *info = [[MPNowPlayingInfoCenter defaultCenter] nowPlayingInfo];
NSString *title = [info valueForKey:MPMediaItemPropertyTitle];
NSString *author = [info valueForKey:MPMediaItemPropertyArtist];
NSLog(@"Currently playing: %@ // %@", title, author);
I Ja get Currently playing: (null) // (null)
Zbadałem to dość dużo i poniższe artykuły wyjaśniają to dość dokładnie, jednak nadal nie jestem w stanie tego poprawnie uruchomić. Coś przeoczyłem? Czy coś mogłoby w tym przeszkodzić? Czy jest to usługa, do której moja aplikacja musi się zarejestrować, aby uzyskać dostęp (nie widziałem tego w żadnych dokumentach)?
2 answers
W końcu rozgryzłem problem, nie prosiłem mojej aplikacji o odbieranie zdarzeń zdalnego sterowania, po prostu dodanie tej linii naprawiło problem:
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-03-02 16:47:47
Używam poniższego kodu i zawsze działa. Używam też MPMoviePlayer
jak ty. Czy sprawdziłeś, czy NSClassFromString(@"MPNowPlayingInfoCenter")
kiedykolwiek rzeczywiście zwraca YES
? Czy Ustawiłeś app play audio w kluczu tła w pliście?
- (void) loadMPInformation
{
NSDictionary *mpInfo;
if([savedTrack.belongingAlbum.hasAlbumArt boolValue] == NO){
mpInfo = [NSDictionary dictionaryWithObjectsAndKeys:savedTrack.belongingAlbum.album, MPMediaItemPropertyAlbumTitle,
savedTrack.belongingArtist.artist, MPMediaItemPropertyArtist, savedTrack.name, MPMediaItemPropertyTitle, nil];
} else {
UIImage *artImage = [UIImage imageWithData:savedTrack.belongingAlbum.art];
MPMediaItemArtwork *artwork = [[MPMediaItemArtwork alloc] initWithImage:artImage];
mpInfo = [NSDictionary dictionaryWithObjectsAndKeys:savedTrack.belongingAlbum.album, MPMediaItemPropertyAlbumTitle,
savedTrack.belongingArtist.artist, MPMediaItemPropertyArtist, savedTrack.name, MPMediaItemPropertyTitle, artwork, MPMediaItemPropertyArtwork, nil];
}
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = mpInfo;
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-03-01 19:59:03