Merge branch 'charlesmchen/hardwareRingerVsPlayback'

pull/1/head
Matthew Chen 8 years ago
commit 528b7296d2

@ -26,6 +26,7 @@
#import "UIFont+OWS.h" #import "UIFont+OWS.h"
#import "UIUtil.h" #import "UIUtil.h"
#import "UIView+OWS.h" #import "UIView+OWS.h"
#import "ViewControllerUtils.h"
#import <JSQSystemSoundPlayer.h> #import <JSQSystemSoundPlayer.h>
#import <PureLayout/PureLayout.h> #import <PureLayout/PureLayout.h>
#import <SignalServiceKit/Contact.h> #import <SignalServiceKit/Contact.h>

@ -43,14 +43,26 @@ class AttachmentApprovalViewController: UIViewController {
view.backgroundColor = UIColor.black view.backgroundColor = UIColor.black
self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem:.stop, self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem:.stop,
target:self, target:self,
action:#selector(donePressed)) action:#selector(donePressed))
self.navigationItem.title = NSLocalizedString("ATTACHMENT_APPROVAL_DIALOG_TITLE", self.navigationItem.title = NSLocalizedString("ATTACHMENT_APPROVAL_DIALOG_TITLE",
comment: "Title for the 'attachment approval' dialog.") comment: "Title for the 'attachment approval' dialog.")
createViews() createViews()
} }
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
ViewControllerUtils.setAudioIgnoresHardwareMuteSwitch(true)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
ViewControllerUtils.setAudioIgnoresHardwareMuteSwitch(false)
}
// MARK: - Create Views // MARK: - Create Views
private func createViews() { private func createViews() {

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

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

@ -5,6 +5,7 @@
#import "ViewControllerUtils.h" #import "ViewControllerUtils.h"
#import "PhoneNumber.h" #import "PhoneNumber.h"
#import "StringUtil.h" #import "StringUtil.h"
#import <AVFoundation/AVFoundation.h>
#import <SignalServiceKit/PhoneNumberUtil.h> #import <SignalServiceKit/PhoneNumberUtil.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -68,6 +69,29 @@ NS_ASSUME_NONNULL_BEGIN
[textField setSelectedTextRange:[textField textRangeFromPosition:pos toPosition:pos]]; [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 @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

Loading…
Cancel
Save