About the MPMoviePlayerController class when playing video, there is no sound problem (iOS)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.