Skip to content

Commit 6671cb4

Browse files
author
JmoVxia
committed
增加音波
1 parent 6f4d96f commit 6671cb4

File tree

10 files changed

+461
-23
lines changed

10 files changed

+461
-23
lines changed

CLDemo.xcodeproj/project.pbxproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@
236236
5BA48263253179A80072F9BD /* CLPopupMomentumController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BA48262253179A80072F9BD /* CLPopupMomentumController.swift */; };
237237
5BA4826725317D260072F9BD /* CLMomentumView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BA4826625317D260072F9BD /* CLMomentumView.swift */; };
238238
5BA4826B253192150072F9BD /* UISpringTimingParameters+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BA4826A253192150072F9BD /* UISpringTimingParameters+Extension.swift */; };
239+
5BA6DFDF2667241C00FE6C50 /* CLWaveformView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BA6DFDE2667241C00FE6C50 /* CLWaveformView.swift */; };
240+
5BA6DFE12667250D00FE6C50 /* CLSampleDataProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BA6DFE02667250D00FE6C50 /* CLSampleDataProvider.swift */; };
241+
5BA6DFE32667258800FE6C50 /* CLSampleDataFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BA6DFE22667258800FE6C50 /* CLSampleDataFilter.swift */; };
239242
5BA7BF7124AC3D180072B94C /* CLPopupTipsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BA7BF4524AC3D180072B94C /* CLPopupTipsController.swift */; };
240243
5BA7BF7224AC3D180072B94C /* CLPopupManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BA7BF4624AC3D180072B94C /* CLPopupManager.swift */; };
241244
5BA7BF7324AC3D180072B94C /* CLPopupFoodPickerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BA7BF4824AC3D180072B94C /* CLPopupFoodPickerController.swift */; };
@@ -688,6 +691,9 @@
688691
5BA48262253179A80072F9BD /* CLPopupMomentumController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CLPopupMomentumController.swift; sourceTree = "<group>"; };
689692
5BA4826625317D260072F9BD /* CLMomentumView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CLMomentumView.swift; sourceTree = "<group>"; };
690693
5BA4826A253192150072F9BD /* UISpringTimingParameters+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UISpringTimingParameters+Extension.swift"; sourceTree = "<group>"; };
694+
5BA6DFDE2667241C00FE6C50 /* CLWaveformView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CLWaveformView.swift; sourceTree = "<group>"; };
695+
5BA6DFE02667250D00FE6C50 /* CLSampleDataProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CLSampleDataProvider.swift; sourceTree = "<group>"; };
696+
5BA6DFE22667258800FE6C50 /* CLSampleDataFilter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CLSampleDataFilter.swift; sourceTree = "<group>"; };
691697
5BA7BF4524AC3D180072B94C /* CLPopupTipsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CLPopupTipsController.swift; sourceTree = "<group>"; };
692698
5BA7BF4624AC3D180072B94C /* CLPopupManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CLPopupManager.swift; sourceTree = "<group>"; };
693699
5BA7BF4824AC3D180072B94C /* CLPopupFoodPickerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CLPopupFoodPickerController.swift; sourceTree = "<group>"; };
@@ -2213,6 +2219,16 @@
22132219
path = CLPopupMomentumController;
22142220
sourceTree = "<group>";
22152221
};
2222+
5BA6DFDD2667240400FE6C50 /* CLWaveformView */ = {
2223+
isa = PBXGroup;
2224+
children = (
2225+
5BA6DFDE2667241C00FE6C50 /* CLWaveformView.swift */,
2226+
5BA6DFE02667250D00FE6C50 /* CLSampleDataProvider.swift */,
2227+
5BA6DFE22667258800FE6C50 /* CLSampleDataFilter.swift */,
2228+
);
2229+
path = CLWaveformView;
2230+
sourceTree = "<group>";
2231+
};
22162232
5BA7BF4124AC3D180072B94C /* CLPopupManager */ = {
22172233
isa = PBXGroup;
22182234
children = (
@@ -2363,6 +2379,7 @@
23632379
5BAB9F2B24A3011900BAC6B5 /* CLRecordeEncodeController */ = {
23642380
isa = PBXGroup;
23652381
children = (
2382+
5BA6DFDD2667240400FE6C50 /* CLWaveformView */,
23662383
5BFB19B924ECFDB90074007A /* CLRecorder */,
23672384
5B42F08E24A3918D006861BF /* CLRecordeEncodeController.h */,
23682385
5B42F08F24A3918D006861BF /* CLRecordeEncodeController.m */,
@@ -2758,6 +2775,7 @@
27582775
0C223C772243811200E319E2 /* CLRotateAnimationSwiftController.swift in Sources */,
27592776
0CCDA40022D9D1C5007B41C4 /* CLPhotoBrowserTransitioningDelegate.m in Sources */,
27602777
0C558A9521ED956700C2C096 /* CLPasswordInputView.m in Sources */,
2778+
5BA6DFE32667258800FE6C50 /* CLSampleDataFilter.swift in Sources */,
27612779
0C52EF6D2192949A0079A0E7 /* NSBundle+CLLanguage.m in Sources */,
27622780
0C558AE421EDA2E800C2C096 /* UIColor+CLHex.m in Sources */,
27632781
0C61577822BE1241009AABAC /* CLSectorAnimationView.swift in Sources */,
@@ -2903,6 +2921,7 @@
29032921
5B723152254FAFB200DA1FE9 /* CLChatTextView.swift in Sources */,
29042922
5BA7BF8E24AC3E790072B94C /* CLPopupFlopController.swift in Sources */,
29052923
5B4A1BD5263968F4004A71CB /* CLPlayVideoController.swift in Sources */,
2924+
5BA6DFDF2667241C00FE6C50 /* CLWaveformView.swift in Sources */,
29062925
5B72314C254FAFB200DA1FE9 /* CLChatPhotoCellButton.swift in Sources */,
29072926
0CCDA40222D9D1C5007B41C4 /* CLPhotoBrowserAnimatedTransitioning.m in Sources */,
29082927
5B44D12C2435C6F10059476D /* CLTagsFrameHelper.swift in Sources */,
@@ -2996,6 +3015,7 @@
29963015
5B80DA581DDD9C3A00A20E34 /* CLTabbarController.m in Sources */,
29973016
5B28650E21EE428200334E6C /* CLCoreTextView.m in Sources */,
29983017
5B8AFC5D24A8829A00FAF996 /* CLVoicePlayer.m in Sources */,
3018+
5BA6DFE12667250D00FE6C50 /* CLSampleDataProvider.swift in Sources */,
29993019
5BB29F312609E6E900A119FE /* CLDrawerSlideAnimation.swift in Sources */,
30003020
5B723153254FAFB200DA1FE9 /* CLChatRecordView.swift in Sources */,
30013021
5B9A13042599D03A00A95209 /* CLStartsView.swift in Sources */,
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1250"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "5B80D9E31DDD976A00A20E34"
18+
BuildableName = "CLDemo.app"
19+
BlueprintName = "CLDemo"
20+
ReferencedContainer = "container:CLDemo.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Debug"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
<BuildableProductRunnable
44+
runnableDebuggingMode = "0">
45+
<BuildableReference
46+
BuildableIdentifier = "primary"
47+
BlueprintIdentifier = "5B80D9E31DDD976A00A20E34"
48+
BuildableName = "CLDemo.app"
49+
BlueprintName = "CLDemo"
50+
ReferencedContainer = "container:CLDemo.xcodeproj">
51+
</BuildableReference>
52+
</BuildableProductRunnable>
53+
</LaunchAction>
54+
<ProfileAction
55+
buildConfiguration = "Release"
56+
shouldUseLaunchSchemeArgsEnv = "YES"
57+
savedToolIdentifier = ""
58+
useCustomWorkingDirectory = "NO"
59+
debugDocumentVersioning = "YES">
60+
<BuildableProductRunnable
61+
runnableDebuggingMode = "0">
62+
<BuildableReference
63+
BuildableIdentifier = "primary"
64+
BlueprintIdentifier = "5B80D9E31DDD976A00A20E34"
65+
BuildableName = "CLDemo.app"
66+
BlueprintName = "CLDemo"
67+
ReferencedContainer = "container:CLDemo.xcodeproj">
68+
</BuildableReference>
69+
</BuildableProductRunnable>
70+
</ProfileAction>
71+
<AnalyzeAction
72+
buildConfiguration = "Debug">
73+
</AnalyzeAction>
74+
<ArchiveAction
75+
buildConfiguration = "Release"
76+
revealArchiveInOrganizer = "YES">
77+
</ArchiveAction>
78+
</Scheme>

CLDemo.xcodeproj/xcuserdata/jmovxia.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,13 @@
1010
<integer>15</integer>
1111
</dict>
1212
</dict>
13+
<key>SuppressBuildableAutocreation</key>
14+
<dict>
15+
<key>5B80D9E31DDD976A00A20E34</key>
16+
<dict>
17+
<key>primary</key>
18+
<true/>
19+
</dict>
20+
</dict>
1321
</dict>
1422
</plist>
Binary file not shown.

CLDemo/Class/Homepage/Controller/CLPlayGifController/CLGifPlayer.swift

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ class CLGifPlayer: NSObject {
2525
queue.maxConcurrentOperationCount = 10
2626
return queue
2727
}()
28-
private override init() {
29-
30-
}
3128
private lazy var operationSemap: DispatchSemaphore = {
3229
let semap = DispatchSemaphore(value: 0)
3330
semap.signal()
3431
return semap
3532
}()
33+
private override init() {
34+
35+
}
3636
deinit {
3737
CLLog("CLGifPlayer deinit")
3838
}
@@ -42,26 +42,22 @@ extension CLGifPlayer {
4242
cancel(path)
4343
let gifOperation = CLGifOperation(path: path, imageCallback: imageCallback)
4444
gifOperation.completionBlock = {
45-
shared.operationSemap.wait()
46-
shared.operationDictionary.removeValue(forKey: path)
47-
shared.operationSemap.signal()
45+
removeValue(path)
4846
startPlay(path, imageCallback: imageCallback)
4947
}
50-
shared.operationDictionary[path] = gifOperation
48+
setOperation(gifOperation, for: path)
5149
shared.operationQueue.addOperation(gifOperation)
5250
}
5351
static func cancel(_ path: String) {
54-
guard let operation = shared.operationDictionary[path],
52+
guard let operation = operation(path),
5553
!operation.isCancelled
5654
else {
5755
return
5856
}
5957
operation.imageCallback = nil
6058
operation.completionBlock = nil
6159
operation.cancel()
62-
shared.operationSemap.wait()
63-
shared.operationDictionary.removeValue(forKey: path)
64-
shared.operationSemap.signal()
60+
removeValue(path)
6561
}
6662
static func cacanAll() {
6763
shared.operationDictionary.keys.forEach { key in
@@ -74,3 +70,21 @@ extension CLGifPlayer {
7470
manager = nil
7571
}
7672
}
73+
private extension CLGifPlayer {
74+
static func operation(_ value: String) -> CLGifOperation? {
75+
shared.operationSemap.wait()
76+
let operation = shared.operationDictionary[value]
77+
shared.operationSemap.signal()
78+
return operation
79+
}
80+
static func setOperation(_ value: CLGifOperation, for key: String) {
81+
shared.operationSemap.wait()
82+
shared.operationDictionary[key] = value
83+
shared.operationSemap.signal()
84+
}
85+
static func removeValue(_ value: String) {
86+
shared.operationSemap.wait()
87+
shared.operationDictionary.removeValue(forKey: value)
88+
shared.operationSemap.signal()
89+
}
90+
}

CLDemo/Class/Homepage/Controller/CLPlayVideoController/CLVideoPlayer.swift

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class CLVideoPlayer: NSObject {
2525
queue.maxConcurrentOperationCount = 10
2626
return queue
2727
}()
28+
private lazy var operationSemap: DispatchSemaphore = {
29+
let semap = DispatchSemaphore(value: 0)
30+
semap.signal()
31+
return semap
32+
}()
2833
private override init() {
2934

3035
}
@@ -37,22 +42,22 @@ extension CLVideoPlayer {
3742
cancel(path)
3843
let videoOperation = CLVideoOperation(path: path, imageCallback: imageCallback)
3944
videoOperation.completionBlock = {
40-
shared.operationDictionary.removeValue(forKey: path)
45+
removeValue(path)
4146
startPlay(path, imageCallback: imageCallback)
4247
}
43-
shared.operationDictionary[path] = videoOperation
48+
setOperation(videoOperation, for: path)
4449
shared.operationQueue.addOperation(videoOperation)
4550
}
4651
static func cancel(_ path: String) {
47-
guard let operation = shared.operationDictionary[path],
52+
guard let operation = operation(path),
4853
!operation.isCancelled
4954
else {
5055
return
5156
}
5257
operation.imageCallback = nil
5358
operation.completionBlock = nil
5459
operation.cancel()
55-
shared.operationDictionary.removeValue(forKey: path)
60+
removeValue(path)
5661
}
5762
static func cacanAll() {
5863
shared.operationDictionary.keys.forEach { key in
@@ -65,3 +70,21 @@ extension CLVideoPlayer {
6570
manager = nil
6671
}
6772
}
73+
private extension CLVideoPlayer {
74+
static func operation(_ value: String) -> CLVideoOperation? {
75+
shared.operationSemap.wait()
76+
let operation = shared.operationDictionary[value]
77+
shared.operationSemap.signal()
78+
return operation
79+
}
80+
static func setOperation(_ value: CLVideoOperation, for key: String) {
81+
shared.operationSemap.wait()
82+
shared.operationDictionary[key] = value
83+
shared.operationSemap.signal()
84+
}
85+
static func removeValue(_ value: String) {
86+
shared.operationSemap.wait()
87+
shared.operationDictionary.removeValue(forKey: value)
88+
shared.operationSemap.signal()
89+
}
90+
}

CLDemo/Class/Homepage/Controller/CLRecordeEncodeController/CLRecordeEncodeController.m

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ @interface CLRecordeEncodeController ()
2020
@property (nonatomic, strong) UILabel *timeLabel;
2121
@property (nonatomic, strong) CLRecorder *recorder;
2222
@property (nonatomic, strong) CLVoicePlayer *player;
23+
@property (nonatomic, strong) CLWaveformView *waveformView;
24+
2325

2426
@end
2527

@@ -32,9 +34,10 @@ - (void)viewDidLoad {
3234
__typeof(&*weakSelf) strongSelf = weakSelf;
3335
strongSelf.timeLabel.text = [strongSelf getMMSSFromSS: seconds];
3436
};
35-
[self.view addSubview:self.startButton];
36-
[self.view addSubview:self.playButton];
37-
[self.view addSubview:self.timeLabel];
37+
[self.view addSubview: self.startButton];
38+
[self.view addSubview: self.playButton];
39+
[self.view addSubview: self.waveformView];
40+
[self.view addSubview: self.timeLabel];
3841
[self.startButton mas_makeConstraints:^(MASConstraintMaker *make) {
3942
make.left.mas_equalTo(90);
4043
make.top.mas_equalTo(200);
@@ -43,11 +46,17 @@ - (void)viewDidLoad {
4346
make.top.mas_equalTo(200);
4447
make.right.mas_equalTo(-90);
4548
}];
49+
[self.waveformView mas_makeConstraints:^(MASConstraintMaker *make) {
50+
make.left.mas_equalTo(20);
51+
make.right.mas_equalTo(-20);
52+
make.height.mas_equalTo(50);
53+
make.centerY.mas_equalTo(self.view);
54+
}];
4655
[self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
47-
make.center.mas_equalTo(self.view);
56+
make.centerX.mas_equalTo(self.view);
57+
make.top.mas_equalTo(self.waveformView.mas_bottom).offset(30);
4858
}];
4959
}
50-
5160
- (void)startAction {
5261
if (!self.startButton.selected) {
5362
NSTimeInterval start = [[NSDate date] timeIntervalSince1970];
@@ -81,7 +90,9 @@ - (NSString *)getMMSSFromSS:(NSUInteger)seconds {
8190
NSString *format_time = [NSString stringWithFormat:@"%@:%@:%@",str_hour,str_minute,str_second];
8291
return format_time;
8392
}
84-
93+
- (void)showWaveform {
94+
self.waveformView.asset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath: self.recorder.mp3Path] options:nil];
95+
}
8596
- (UIButton *)startButton {
8697
if (!_startButton) {
8798
_startButton = [[UIButton alloc] init];
@@ -111,12 +122,19 @@ - (UILabel *)timeLabel {
111122
}
112123
return _timeLabel;
113124
}
125+
- (CLWaveformView *)waveformView {
126+
if (!_waveformView) {
127+
_waveformView = [[CLWaveformView alloc] init];
128+
}
129+
return _waveformView;
130+
}
114131
- (CLRecorder *)recorder {
115132
if (!_recorder) {
116133
_recorder = [[CLRecorder alloc] init];
134+
__weak typeof(self) weakSelf = self;
117135
_recorder.finishCallBack = ^(CGFloat audioDuration, NSData * _Nonnull fileData) {
118-
CLLog(@"%f", audioDuration);
119-
136+
__strong typeof(self) strongSelf = weakSelf;
137+
[strongSelf showWaveform];
120138
};
121139
}
122140
return _recorder;

0 commit comments

Comments
 (0)