如何在 iOS 中将 AVPlayer 控制器设置为锁定模式?
How to set AVPlayer controller in lock mode in iOS?
如何设置背景 iOS 像这样的媒体 AVPlayer
需要左右手球员。
到目前为止我所拥有的
播放、暂停、上一首、下一首都有效。
我需要显示 songName、artistName、albumArt、seekBar。
您需要像这样在MPNowPlayingInfoCenter中设置信息。
Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
if (playingInfoCenter) {
NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage: [UIImage imageNamed:@"AlbumArt"]];
NSArray *keys = [NSArray arrayWithObjects:
MPMediaItemPropertyTitle,
MPMediaItemPropertyArtist,
MPMediaItemPropertyPlaybackDuration,
MPNowPlayingInfoPropertyPlaybackRate,
nil];
NSError *playerError;
// AVAudioPlayer* audioPlayer4 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"This That (Dil Wali Gal) - Ammy Virk (DJJOhAL.Com)" ofType:@".mp3"]] error:&playerError];
//
// NSLog(@"%f",audioPlayer4.duration);
NSArray *values = [NSArray arrayWithObjects:
@"DIL vali gal",
@"ammy virk",
@"30",
[NSNumber numberWithInt:1],
nil];
NSDictionary *mediaInfo = [NSDictionary dictionaryWithObjects:values forKeys:keys];
[songInfo setObject:@"Audio Title" forKey:MPMediaItemPropertyTitle];
[songInfo setObject:@"Audio Author" forKey:MPMediaItemPropertyArtist];
[songInfo setObject:@"Audio Album" forKey:MPMediaItemPropertyAlbumTitle];
[songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:mediaInfo];
}
并导入这个框架
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MPMoviePlayerController.h>
如何设置背景 iOS 像这样的媒体 AVPlayer
需要左右手球员。
到目前为止我所拥有的
播放、暂停、上一首、下一首都有效。
我需要显示 songName、artistName、albumArt、seekBar。
您需要像这样在MPNowPlayingInfoCenter中设置信息。
Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter");
if (playingInfoCenter) {
NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage: [UIImage imageNamed:@"AlbumArt"]];
NSArray *keys = [NSArray arrayWithObjects:
MPMediaItemPropertyTitle,
MPMediaItemPropertyArtist,
MPMediaItemPropertyPlaybackDuration,
MPNowPlayingInfoPropertyPlaybackRate,
nil];
NSError *playerError;
// AVAudioPlayer* audioPlayer4 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"This That (Dil Wali Gal) - Ammy Virk (DJJOhAL.Com)" ofType:@".mp3"]] error:&playerError];
//
// NSLog(@"%f",audioPlayer4.duration);
NSArray *values = [NSArray arrayWithObjects:
@"DIL vali gal",
@"ammy virk",
@"30",
[NSNumber numberWithInt:1],
nil];
NSDictionary *mediaInfo = [NSDictionary dictionaryWithObjects:values forKeys:keys];
[songInfo setObject:@"Audio Title" forKey:MPMediaItemPropertyTitle];
[songInfo setObject:@"Audio Author" forKey:MPMediaItemPropertyArtist];
[songInfo setObject:@"Audio Album" forKey:MPMediaItemPropertyAlbumTitle];
[songInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];
[[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:mediaInfo];
}
并导入这个框架
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MPMoviePlayerController.h>