-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathVolumeSlider.m
More file actions
128 lines (96 loc) · 3.21 KB
/
VolumeSlider.m
File metadata and controls
128 lines (96 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//
// VolumeSlider.m
// Volume Slider Cordova Plugin
//
// Created by Tommy-Carlos Williams on 20/07/11. Updated by Samuel Michelot on 11/05/1013
// Copyright 2011 Tommy-Carlos Williams. All rights reserved.
// MIT Licensed
//
#import "VolumeSlider.h"
#import <MediaPlayer/MediaPlayer.h>
@implementation VolumeSlider
@synthesize mpVolumeViewParentView, myVolumeView, callbackId;
float userVolume = 0.2;
UISlider* volumeViewSlider = nil;
#ifndef __IPHONE_3_0
@synthesize webView;
#endif
-(CDVPlugin*) initWithWebView:(UIWebView*)theWebView
{
self = (VolumeSlider*)[super initWithWebView:theWebView];
return self;
}
#pragma mark -
#pragma mark VolumeSlider
- (void) createVolumeSlider:(CDVInvokedUrlCommand *)command
{
NSLog(@"In createVolumeSlider");
NSArray* arguments = [command arguments];
self.callbackId = command.callbackId;
NSUInteger argc = [arguments count];
if (argc < 3) { // at a minimum we need x origin, y origin and width...
return;
}
if (self.mpVolumeViewParentView != NULL) {
// return;//already created, don't need to create it again
}
CGFloat originx,originy,width;
CGFloat height = 30;
originx = [[arguments objectAtIndex:0] floatValue];
originy = [[arguments objectAtIndex:1] floatValue];
width = [[arguments objectAtIndex:2] floatValue];
if (argc > 3) {
height = [[arguments objectAtIndex:3] floatValue];
}
CGRect viewRect = CGRectMake(
originx,
originy,
width,
height
);
self.mpVolumeViewParentView = [[UIView alloc] initWithFrame:viewRect];
[self.webView.superview addSubview:mpVolumeViewParentView];
mpVolumeViewParentView.backgroundColor = [UIColor clearColor];
self.myVolumeView =
[[MPVolumeView alloc] initWithFrame: mpVolumeViewParentView.bounds];
[mpVolumeViewParentView addSubview: myVolumeView];
self.myVolumeView.showsVolumeSlider = NO;
volumeViewSlider = nil;
for (UIView *view in [self.myVolumeView subviews]){
if ([view.class.description isEqualToString:@"MPVolumeSlider"]){
volumeViewSlider = (UISlider*)view;
NSLog(@"Found MPVolumeslider : %f" ,userVolume );
break;
}
}
userVolume = volumeViewSlider.value;
}
- (void)showVolumeSlider:(CDVInvokedUrlCommand *)command
{
self.myVolumeView.showsVolumeSlider = YES;
self.mpVolumeViewParentView.hidden = NO;
}
- (void)hideVolumeSlider:(CDVInvokedUrlCommand *)command
{
self.mpVolumeViewParentView.hidden = YES;
self.myVolumeView.showsVolumeSlider = NO;
}
- (void)setVolumeSlider:(CDVInvokedUrlCommand *)command
{
self.mpVolumeViewParentView.hidden = YES;
self.myVolumeView.showsVolumeSlider = NO;
NSArray* arguments = [command arguments];
NSUInteger argc = [arguments count];
if (argc < 1) { // at a minimum we need the value to be set...
return;
}
float setVolume = [[arguments objectAtIndex:0] floatValue];
[volumeViewSlider setValue:setVolume animated:NO];
[volumeViewSlider sendActionsForControlEvents:UIControlEventTouchUpInside];
}
- (void)resetVolumeSlider:(CDVInvokedUrlCommand *)command
{
[volumeViewSlider setValue:userVolume animated:NO];
[volumeViewSlider sendActionsForControlEvents:UIControlEventTouchUpInside];
}
@end