Merge branch 'charlesmchen/hardwareRingerVsPlayback'

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

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

@ -43,14 +43,26 @@ class AttachmentApprovalViewController: UIViewController {
view.backgroundColor = UIColor.black
self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem:.stop,
target:self,
action:#selector(donePressed))
target:self,
action:#selector(donePressed))
self.navigationItem.title = NSLocalizedString("ATTACHMENT_APPROVAL_DIALOG_TITLE",
comment: "Title for the 'attachment approval' dialog.")
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
private func createViews() {

@ -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