First, import audio resource class
#import "Avfoundation/avaudiosession.h"
Second, in the method of playing video to add a support for the speaker code
[[avaudiosession sharedinstance] setcategory:avaudiosessioncategoryplayback error:nil];
Refer to the following example
#pragma mark- play Video
-(void) Playmovie: (cgrect) videorect {
// Check network settings
BOOL netavailable = [helptool isconnectionavailable];
if (!netavailable) {
[wsprogresshud showImage:nil status:@ " network is not connected, please check the network settings "];
return;
}
nsurl *url = [nsurl urlwithstring:self. Topicmodel. Videofullurl];
MPMoviePlayerController *player = [[mpmovieplayercontroller alloc] Initwithcontenturl: url];
[self. TableView addsubview:p layer. View];
// calculates the current offset of the tableView
cgpoint offset = self. TableView. Contentoffset;
Videorect. Origin. Y + = offset. Y;
Player. View. Frame = videorect;
Player. ControlStyle = mpmoviecontrolstyleembedded;
// support sound speaker
[[avaudiosession sharedinstance] setcategory:avaudiosessioncategoryplayback error:nil];
[Player Preparetoplay];
[Player play];
self. Player = player;
}
About the MPMoviePlayerController class when playing video, there is no sound problem (iOS)