0

私は音楽プレーヤーを作ろうとしています、これは私がNSLog現在のインデックスを表示するために置いた場所です:

- (void) handle_NowPlayingItemChanged: (id) notification
{
    MPMediaItem *currentItem = [musicPlayer nowPlayingItem];
    NSUInteger currentIndex = [musicPlayer indexOfNowPlayingItem];
    UIImage *artworkImage = [UIImage imageNamed:@"NoSongImage.png"];
    MPMediaItemArtwork *artwork = [currentItem valueForProperty:MPMediaItemPropertyArtwork];

if (artwork) {
    artworkImage = [artwork imageWithSize: CGSizeMake (200, 200)];
}

[self.artwork setImage:artworkImage];

NSString *titleString = [currentItem valueForProperty:MPMediaItemPropertyTitle];
if (titleString) {
    self.songName.text = [NSString stringWithFormat:@"%@",titleString];
} else {
    self.songName.text = @"Unknown title";
}

    NSLog(@"%li", currentIndex);
}

これは私didSelectRowAtIndexPathのものですUITableView

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (songsList == YES){
    NSUInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
    MPMediaItem *selectedItem = [[songs objectAtIndex:selectedIndex] representativeItem];
    [musicPlayer setQueueWithItemCollection:[MPMediaItemCollection collectionWithItems:[songsQuery items]]];
    [musicPlayer setNowPlayingItem:selectedItem];
    [musicPlayer play];
    songsList = NO;
}
else if (albumsList == YES && albumsSongsList == NO){
    albumsSongsList = YES;
    NSUInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
    MPMediaItem *selectedItem = [[albums objectAtIndex:selectedIndex] representativeItem];
    albumTitle = [selectedItem valueForProperty:MPMediaItemPropertyAlbumTitle];
    MPMediaItemArtwork *albumArtwork = [selectedItem valueForProperty:MPMediaItemPropertyArtwork];
    albumSelected = [albumArtwork imageWithSize: CGSizeMake (44, 44)];
    [self.tableView reloadData];
    [self.tableView setContentOffset:CGPointZero animated:NO];
}
else if (albumsSongsList == YES){
    albumsSongsList = NO;
    MPMediaQuery *albumQuery = [MPMediaQuery albumsQuery];
    MPMediaPropertyPredicate *albumPredicate = [MPMediaPropertyPredicate predicateWithValue: albumTitle forProperty: MPMediaItemPropertyAlbumTitle];
    [albumQuery addFilterPredicate:albumPredicate];
    NSArray *albumTracks = [albumQuery items];
    NSUInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
    MPMediaItem *selectedItem = [[albumTracks objectAtIndex:selectedIndex] representativeItem];
    [musicPlayer setQueueWithItemCollection:[MPMediaItemCollection collectionWithItems:[albumQuery items]]];
    [musicPlayer setNowPlayingItem:selectedItem];
    [musicPlayer play];
    }
}

BOOLS は、tableView willDisplayCellロードするテーブルを決定します。上記はすべてUITableView、正しいコンテンツで正しく表示されます。tableView問題は、アルバムを開いて曲を選択すると、代わりにアルバムの最初の曲 (の上部) が再生されるように見えることです。もう一度アルバムに戻って別の曲を選択すると、正しい曲が選択されます。もう一度戻って曲を選択すると、最初の曲が再び再生され、それが繰り返されます...

私の NSLog では、最初の曲を再生する理由currentIndex9223372036854775807

なぜ戻ってくるのNSNotFoundですか?(selectedIndex4) は の配列にありalbumTracksます。これは曲でも 1/3 回発生します。よろしくお願いいたします。

4

2 に答える 2

1

64 ビット システムでの NSNotFound の値は? 2^63 - 1 とは何ですか?

于 2015-09-11T14:47:52.293 に答える