play mp3 file with MPMoviePlayer in background
-
27-06-2021 - |
题
I am using this MPMoviePlayerViewController
to play .mp3
file from server but not working properly.
Here is the code i am using.
NSString *path = @"http://myurl/music.mp3";
MPMoviePlayerViewController *mpviewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:path]];
mpviewController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self presentModalViewController:mpviewController animated:YES];
[[mpviewController moviePlayer] play];
Audio play for 3 or 5 seconds only then it stops automatically. Cant figure out whats the problem. Your suggestions would be great help.
Thank you.
解决方案
Solved it by this code :) May it helps someone.
NSString *path = @"http://myurl/mymusic.mp3";
mv = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:path]];
mv.movieSourceType = MPMovieSourceTypeUnknown;
[self.view addSubview:mv.view];
[mv play];
其他提示
I am using this GIT for audio streaming from my server. it is simple to use repo.
At the time I have imported to my project it didn't have any background playing. I have added that with some simple iOS code.
Maybe you should retain your mpviewController, I make the same misstake.
不隶属于 StackOverflow