2013-11-05 37 views
2

我打算使用Parse.com後端用於用戶認證/帖子/關注者/等我想讓用戶能夠上傳示例音樂文件解析(或備用解決方案),然後能夠流式傳輸或讓其他人能夠流式傳輸。我被告知可以使用PFFile存儲文件,但是如何將它流式傳輸?存儲短音頻文件/流在應用程序

此外,這將違反蘋果的規定,因爲最終它會允許用戶通過應用程序購買這些音樂文件,或者我將不得不使用iTunes帳戶/某種文件?

感謝提前

+0

我不認爲服務器在解析時需要流式傳輸給應用程序的其他用戶所需的'chunked-encoding'。它們針對產量進行了優化。您可以上傳音頻,並讓用戶在打開播放器之前下載整個音頻。 –

+0

人不知道我怎麼會這樣做... – Jason

+0

以及你可以開始閱讀文件上傳文檔https://parse.com/docs/rest#files-uploading你只需把你的二進制音頻文件在POST的主體並使用示例中的api。 –

回答

7

幫助中上傳來解析方面:

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:

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]); 
    } 
}]; 

不能到蘋果是否會讓你賣的音樂在你的應用程序或不說話。

相關問題