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

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

问题描述

我计划开发一个利用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];

在从Parse服务器进行流传输方面,使用允许流传输的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天全站免登陆