在应用程序中存储短音频文件/流媒体 [英] Storing short audio file / Streaming in app

查看:29
本文介绍了在应用程序中存储短音频文件/流媒体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划制作一个利用 Parse.com 后端进行用户身份验证/帖子/关注者等的应用程序.我希望用户能够将示例音乐文件上传到 Parse(或替代解决方案)然后能够流式传输或让其他人能够流式传输它.有人告诉我可以使用 PFFile 存储文件,但就流式传输而言如何?

I plan on making an app that utilizes the Parse.com backend for User authentication / Posts / Followers / etc. I want for users to be able to upload a sample music file to Parse (or an alternate solution) then be able to stream or have others be able to stream it. I was told it's possible to store the file using PFFile, but how about as far as streaming it?

这是否也违反了 Apple 的规定,因为最终它将允许用户通过应用程序购买这些音乐文件,还是我必须使用某种形式的 iTunes 帐户/文件?

Also would this be against Apple rules since ultimately it will allow users to buy these music files through the app, or would I have to use iTunes accounts/files of some sort?

提前感谢您的帮助

推荐答案

上传解析方面:

PFObject *testObject = [PFObject objectWithClassName:@"TestObject"];

//get the audio in NSData format
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"02 Interstellar Overdrive" ofType:@"m4a"];
NSData *audioData = [NSData dataWithContentsOfFile:filePath];

//create PFFile to store audio data
PFFile *audioFile = [PFFile fileWithName:@"02 Interstellar Overdrive.m4a" data:audioData];
testObject[@"audioFile"] = audioFile;

//save
[testObject saveInBackground];

就从解析服务器流式传输而言,使用允许流式传输的 AVPlayer.如果您想在播放前先下载整首歌曲,可以使用 AVAudioPlayer:

In terms of streaming it from the Parse servers use AVPlayer which allows streaming. You can use AVAudioPlayer if you want to download the whole song first before playing:

PFQuery *query = [PFQuery queryWithClassName:@"TestObject"];
[query whereKeyExists:@"audioFile"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error)
    {
        PFObject *testObject = [objects lastObject];
        PFFile *audioFile = testObject[@"audioFile"];
        NSString *filePath = [audioFile url];

        //play audiofile streaming
        self.avPlayer = [[AVPlayer alloc] initWithURL:[NSURL URLWithString:filePath]];
        self.avPlayer.volume = 1.0f;
        [self.avPlayer play];

    } else {

        NSLog(@"error = %@", [error userInfo]);
    }
}];

无法确定 Apple 是否会允许您在您的应用中销售音乐.

Can't speak to whether Apple will let you sell music in your app or not.

这篇关于在应用程序中存储短音频文件/流媒体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆