Ignore hardware mute switch during video playback in messages view.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 1cf45a26d0
commit d9ef27d802

@ -43,6 +43,7 @@
#import "UIUtil.h"
#import "UIViewController+CameraPermissions.h"
#import "UIViewController+OWS.h"
#import "ViewControllerUtils.h"
#import <AddressBookUI/AddressBookUI.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import <ContactsUI/CNContactViewController.h>
@ -1681,7 +1682,8 @@ typedef enum : NSUInteger {
if ([messageMedia isVideo]) {
if ([fileManager fileExistsAtPath:[attStream.mediaURL path]]) {
[self dismissKeyBoard];
_videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:attStream.mediaURL];
self.videoPlayer =
[[MPMoviePlayerController alloc] initWithContentURL:attStream.mediaURL];
[_videoPlayer prepareToPlay];
[[NSNotificationCenter defaultCenter] addObserver:self
@ -1876,7 +1878,14 @@ typedef enum : NSUInteger {
- (void)clearVideoPlayer {
[_videoPlayer stop];
[_videoPlayer.view removeFromSuperview];
_videoPlayer = nil;
self.videoPlayer = nil;
}
- (void)setVideoPlayer:(MPMoviePlayerController *)videoPlayer
{
_videoPlayer = videoPlayer;
[ViewControllerUtils setAudioIgnoresHardwareMuteSwitch:videoPlayer != nil];
}
- (void)collectionView:(JSQMessagesCollectionView *)collectionView

@ -16,4 +16,6 @@
replacementString:(NSString *)insertionText
countryCode:(NSString *)countryCode;
+ (void)setAudioIgnoresHardwareMuteSwitch:(BOOL)shouldIgnore;
@end

@ -5,6 +5,7 @@
#import "ViewControllerUtils.h"
#import "PhoneNumber.h"
#import "StringUtil.h"
#import <AVFoundation/AVFoundation.h>
#import <SignalServiceKit/PhoneNumberUtil.h>
NS_ASSUME_NONNULL_BEGIN
@ -68,6 +69,29 @@ NS_ASSUME_NONNULL_BEGIN
[textField setSelectedTextRange:[textField textRangeFromPosition:pos toPosition:pos]];
}
+ (void)setAudioIgnoresHardwareMuteSwitch:(BOOL)shouldIgnore
{
NSError *error = nil;
BOOL success = [[AVAudioSession sharedInstance]
setCategory:(shouldIgnore ? AVAudioSessionCategoryPlayback : AVAudioSessionCategoryPlayAndRecord)error:&error];
OWSAssert(!error);
if (!success || error) {
DDLogError(@"%@ Error in setAudioIgnoresHardwareMuteSwitch: %d", self.tag, shouldIgnore);
}
}
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.tag;
}
@end
NS_ASSUME_NONNULL_END

Loading…
Cancel
Save