如何制作 iPod 音乐应用程序? AVPlayer - AVAudioPlayer - MPMusicPlayController
我在文档目录中有一个歌曲列表.. 这是获取这些歌曲的代码...
NSArray *pathSong = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectorySong = [pathSong objectAtIndex:0];
NSFileManager *managerSong = [NSFileManager defaultManager];
NSString *dataPath = [documentsDirectorySong stringByAppendingPathComponent:@"/Downloads"];
NSString *folPath = [dataPath stringByAppendingPathComponent:@"/Folder"];
NSArray *fileListSong = [managerSong contentsOfDirectoryAtPath:[dataPath stringByAppendingPathComponent:@"/Folder"]error:nil];
之后,这些歌曲在 iPod 音乐库等播放器中播放。
我尝试使用 MPMusicPlayController
但它仅用于从音乐库中选取歌曲,而不是从文档目录中选取歌曲应用程序..
还尝试使用 AVAudioPlayer 但无法获取当前播放歌曲的 Artist、AlbumName、Title、ArtImage 属性..
这里也是 AVPlayer
的代码,
但它从库中获取数据,我只想从文档目录..
MPMediaQuery *query = [MPMediaQuery songsQuery];
NSArray *songs = query.items;
NSURL *itemURL = [currentItem valueForProperty:MPMediaItemPropertyAssetURL];
if (!avPlayer) {
avPlayer = [[AVPlayer alloc] initWithURL:itemURL];
} else {
[avPlayer replaceCurrentItemWithPlayerItem:[AVPlayerItem playerItemWithURL:itemURL]];
avPlayer.rate = 0.0f;
}
但无法从文档目录获取歌曲,
任何人都可以解释我最好使用哪种播放器吗?
我正在制作音乐播放器,就像 iPod 音乐应用程序一样。
I have a songs list in document directory..
Here is a code for fetching those songs...
NSArray *pathSong = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectorySong = [pathSong objectAtIndex:0];
NSFileManager *managerSong = [NSFileManager defaultManager];
NSString *dataPath = [documentsDirectorySong stringByAppendingPathComponent:@"/Downloads"];
NSString *folPath = [dataPath stringByAppendingPathComponent:@"/Folder"];
NSArray *fileListSong = [managerSong contentsOfDirectoryAtPath:[dataPath stringByAppendingPathComponent:@"/Folder"]error:nil];
After that these songs play in player like iPod music library..
I have try with MPMusicPlayController
but its only for picking songs from music library not from document directory of the app..
Also try with AVAudioPlayer but cant get Artist, AlbumName, Title , ArtImage property of current playing song..
here is a also code of AVPlayer
But its fetch data from library, And I want only from document directory..
MPMediaQuery *query = [MPMediaQuery songsQuery];
NSArray *songs = query.items;
NSURL *itemURL = [currentItem valueForProperty:MPMediaItemPropertyAssetURL];
if (!avPlayer) {
avPlayer = [[AVPlayer alloc] initWithURL:itemURL];
} else {
[avPlayer replaceCurrentItemWithPlayerItem:[AVPlayerItem playerItemWithURL:itemURL]];
avPlayer.rate = 0.0f;
}
But not get songs from Document Directory,
Can any one explain me which player better to use ?
i am making music player as like iPod Music app..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论