Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Unified Diff: webrtc/examples/objc/AppRTCDemo/ios/ARDMainView.m

Issue 1710053004: Add looping sound button to AppRTCDemo (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Back to rtc_base Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrtc/examples/objc/AppRTCDemo/ios/resources/mozart.mp3 » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/examples/objc/AppRTCDemo/ios/ARDMainView.m
diff --git a/webrtc/examples/objc/AppRTCDemo/ios/ARDMainView.m b/webrtc/examples/objc/AppRTCDemo/ios/ARDMainView.m
index e809cb302795490bedb4bafd716565fee1f1c1c3..6f526573e33cde11abceec0dbbea4de40689c611 100644
--- a/webrtc/examples/objc/AppRTCDemo/ios/ARDMainView.m
+++ b/webrtc/examples/objc/AppRTCDemo/ios/ARDMainView.m
@@ -10,6 +10,8 @@
#import "ARDMainView.h"
+#import <AVFoundation/AVFoundation.h>
+
#import "UIImage+ARDUtilities.h"
// TODO(tkchin): retrieve status bar height dynamically.
@@ -123,12 +125,23 @@ static CGFloat const kAppLabelHeight = 20;
UISwitch *_loopbackSwitch;
UILabel *_loopbackLabel;
UIButton *_startCallButton;
+ UIButton *_audioLoopButton;
+ AVAudioPlayer *_audioPlayer;
}
@synthesize delegate = _delegate;
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
+ NSString *audioFilePath =
+ [[NSBundle mainBundle] pathForResource:@"mozart" ofType:@"mp3"];
+ NSURL *audioFileURL = [NSURL URLWithString:audioFilePath];
+ _audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileURL
+ error:nil];
+ _audioPlayer.numberOfLoops = -1;
+ _audioPlayer.volume = 1.0;
+ [_audioPlayer prepareToPlay];
+
_appLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_appLabel.text = @"AppRTCDemo";
_appLabel.font = [UIFont fontWithName:@"Roboto" size:34];
@@ -171,8 +184,6 @@ static CGFloat const kAppLabelHeight = 20;
[_loopbackLabel sizeToFit];
[self addSubview:_loopbackLabel];
- _startCallButton = [[UIButton alloc] initWithFrame:CGRectZero];
-
_startCallButton = [UIButton buttonWithType:UIButtonTypeSystem];
_startCallButton.backgroundColor = [UIColor blueColor];
_startCallButton.layer.cornerRadius = 10;
@@ -191,6 +202,22 @@ static CGFloat const kAppLabelHeight = 20;
forControlEvents:UIControlEventTouchUpInside];
[self addSubview:_startCallButton];
+ // Used to test what happens to sounds when calls are in progress.
+ _audioLoopButton = [UIButton buttonWithType:UIButtonTypeSystem];
+ _audioLoopButton.layer.cornerRadius = 10;
+ _audioLoopButton.clipsToBounds = YES;
+ _audioLoopButton.contentEdgeInsets = UIEdgeInsetsMake(5, 10, 5, 10);
+ _audioLoopButton.titleLabel.font = controlFont;
+ [_audioLoopButton setTitleColor:[UIColor whiteColor]
+ forState:UIControlStateNormal];
+ [_audioLoopButton setTitleColor:[UIColor lightGrayColor]
+ forState:UIControlStateSelected];
+ [self updateAudioLoopButton];
+ [_audioLoopButton addTarget:self
+ action:@selector(onToggleAudioLoop:)
+ forControlEvents:UIControlEventTouchUpInside];
+ [self addSubview:_audioLoopButton];
+
self.backgroundColor = [UIColor whiteColor];
}
return self;
@@ -237,8 +264,15 @@ static CGFloat const kAppLabelHeight = 20;
_loopbackLabel.center = CGPointMake(loopbackModeLabelCenterX,
CGRectGetMidY(loopbackModeRect));
- CGFloat startCallTop =
+ CGFloat audioLoopTop =
CGRectGetMaxY(loopbackModeRect) + kCallControlMargin * 3;
+ _audioLoopButton.frame = CGRectMake(kCallControlMargin,
+ audioLoopTop,
+ _audioLoopButton.frame.size.width,
+ _audioLoopButton.frame.size.height);
+
+ CGFloat startCallTop =
+ CGRectGetMaxY(_audioLoopButton.frame) + kCallControlMargin * 3;
_startCallButton.frame = CGRectMake(kCallControlMargin,
startCallTop,
_startCallButton.frame.size.width,
@@ -247,6 +281,29 @@ static CGFloat const kAppLabelHeight = 20;
#pragma mark - Private
+- (void)updateAudioLoopButton {
+ if (_audioPlayer.playing) {
+ _audioLoopButton.backgroundColor = [UIColor redColor];
+ [_audioLoopButton setTitle:@"Stop sound"
+ forState:UIControlStateNormal];
+ [_audioLoopButton sizeToFit];
+ } else {
+ _audioLoopButton.backgroundColor = [UIColor greenColor];
+ [_audioLoopButton setTitle:@"Play sound"
+ forState:UIControlStateNormal];
+ [_audioLoopButton sizeToFit];
+ }
+}
+
+- (void)onToggleAudioLoop:(id)sender {
+ if (_audioPlayer.playing) {
+ [_audioPlayer stop];
+ } else {
+ [_audioPlayer play];
+ }
+ [self updateAudioLoopButton];
+}
+
- (void)onStartCall:(id)sender {
NSString *room = _roomText.roomText;
// If this is a loopback call, allow a generated room name.
« no previous file with comments | « no previous file | webrtc/examples/objc/AppRTCDemo/ios/resources/mozart.mp3 » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698