如何制作 iPod 音乐应用程序? AVPlayer - AVAudioPlayer - MPMusicPlayController

发布于 2024-12-14 09:59:00 字数 1371 浏览 0 评论 0原文

我在文档目录中有一个歌曲列表.. 这是获取这些歌曲的代码...

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文