Praveenkumar
Praveenkumar

Reputation: 24506

MPMoviePlayerController streaming video not play Audio on iPad

This may be a silly question. But, don't know where the problem actually. I'm trying to stream my http streaming (HLS) through MPMoviePlayercontroller video streaming is fine. But, audio isn't working on real device (Working in Simulator) Here is my code,

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://mydomain:1935/coder/%@/playlist.m3u8", self.streamField.text]];
theMoviPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
theMoviPlayer.controlStyle = MPMovieControlStyleFullscreen;
theMoviPlayer.movieSourceType = MPMovieSourceTypeStreaming;
theMoviPlayer.view.transform = CGAffineTransformConcat(theMoviPlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
UIWindow *backgroundWindow = [[UIApplication sharedApplication] keyWindow];
[theMoviPlayer.view setFrame:backgroundWindow.frame];
[backgroundWindow addSubview:theMoviPlayer.view];
[theMoviPlayer play];

Has anyone worked on this? I'm getting only with device for audio issue.

Edit

I have tried below one,

NSURL *url = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
MPMoviePlayerViewController  *player = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:player];

This(URL only given to safari) works fine both iPad and Simulator iPad of Safari browser with Audio. But, not working as application on iPad except Simulator.

Upvotes: 1

Views: 2608

Answers (1)

ssmanohar
ssmanohar

Reputation: 186

First add AVFoundation.framework and add below code.

in .h file

 #import <AVFoundation/AVFoundation.h>

and .m file

 [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];

Upvotes: 11

Related Questions