gpt4 book ai didi

ios - MPMediaPlayer indexOfNowPlayingItem 给出当前索引 9223372036854775807

转载 作者:行者123 更新时间:2023-11-29 01:39:55 26 4
gpt4 key购买 nike

我正在尝试制作一个音乐播放器,这是我放置 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);
}

这是我的 UITableViewdidSelectRowAtIndexPath:

-(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

为什么它返回NSNotFoundselectedIndex(例如4)位于albumTracks数组中。对于歌曲来说,这种情况也发生了 1/3 次。非常感谢您的帮助。

最佳答案

NSNotFound 在 64 位系统上的值(value)是什么?什么是 2^63 - 1?

关于ios - MPMediaPlayer indexOfNowPlayingItem 给出当前索引 9223372036854775807,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32526183/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com