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

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: 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/webrtc_examples.gyp » ('j') | webrtc/webrtc_examples.gyp » ('J')
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..71baa889284fb063803b5da88ef81b20f42c846f 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 *_soundLoopButton;
+ AVAudioPlayer *_audioPlayer;
}
@synthesize delegate = _delegate;
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
+ NSString *outgoingRingFilePath =
+ [[NSBundle mainBundle] pathForResource:@"outgoing_ring" ofType:@"mp3"];
+ NSURL *outgoingRingURL = [NSURL URLWithString:outgoingRingFilePath];
+ _audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:outgoingRingURL
+ 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.
+ _soundLoopButton = [UIButton buttonWithType:UIButtonTypeSystem];
+ _soundLoopButton.layer.cornerRadius = 10;
+ _soundLoopButton.clipsToBounds = YES;
+ _soundLoopButton.contentEdgeInsets = UIEdgeInsetsMake(5, 10, 5, 10);
+ _soundLoopButton.titleLabel.font = controlFont;
+ [_soundLoopButton setTitleColor:[UIColor whiteColor]
+ forState:UIControlStateNormal];
+ [_soundLoopButton setTitleColor:[UIColor lightGrayColor]
+ forState:UIControlStateSelected];
+ [self updateSoundButton];
+ [_soundLoopButton addTarget:self
+ action:@selector(onToggleSound:)
+ forControlEvents:UIControlEventTouchUpInside];
+ [self addSubview:_soundLoopButton];
+
self.backgroundColor = [UIColor whiteColor];
}
return self;
@@ -237,8 +264,15 @@ static CGFloat const kAppLabelHeight = 20;
_loopbackLabel.center = CGPointMake(loopbackModeLabelCenterX,
CGRectGetMidY(loopbackModeRect));
- CGFloat startCallTop =
+ CGFloat soundToggleTop =
CGRectGetMaxY(loopbackModeRect) + kCallControlMargin * 3;
+ _soundLoopButton.frame = CGRectMake(kCallControlMargin,
+ soundToggleTop,
+ _soundLoopButton.frame.size.width,
+ _soundLoopButton.frame.size.height);
+
+ CGFloat startCallTop =
+ CGRectGetMaxY(_soundLoopButton.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)updateSoundButton {
+ if (_audioPlayer.playing) {
+ _soundLoopButton.backgroundColor = [UIColor redColor];
+ [_soundLoopButton setTitle:@"Stop sound"
+ forState:UIControlStateNormal];
+ [_soundLoopButton sizeToFit];
+ } else {
+ _soundLoopButton.backgroundColor = [UIColor greenColor];
+ [_soundLoopButton setTitle:@"Play sound"
+ forState:UIControlStateNormal];
+ [_soundLoopButton sizeToFit];
+ }
+}
+
+- (void)onToggleSound:(id)sender {
+ if (_audioPlayer.playing) {
+ [_audioPlayer stop];
+ } else {
+ [_audioPlayer play];
+ }
+ [self updateSoundButton];
+}
+
- (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/webrtc_examples.gyp » ('j') | webrtc/webrtc_examples.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698