Skip to content
This repository was archived by the owner on May 18, 2022. It is now read-only.

Commit 1bf90e1

Browse files
committed
ios build done.
1 parent 3ecf659 commit 1bf90e1

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

ios/Classes/FlutterSoundPlugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#import <Flutter/Flutter.h>
2+
#import <AVFoundation/AVFoundation.h>
23

34
@interface FlutterSoundPlugin : NSObject<FlutterPlugin, AVAudioPlayerDelegate>
45
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player

ios/Classes/FlutterSoundPlugin.m

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,55 @@
11
#import "FlutterSoundPlugin.h"
22
#import <AVFoundation/AVFoundation.h>
33

4-
@implementation FlutterSoundPlugin
4+
@implementation FlutterSoundPlugin{
55
NSURL *audioFileURL;
66
AVAudioRecorder *audioRecorder;
77
AVAudioPlayer *audioPlayer;
88
NSTimer *timer;
9+
}
10+
11+
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
12+
NSLog(@"audioPlayerDidFinishPlaying");
13+
NSNumber *duration = [NSNumber numberWithDouble:audioPlayer.duration * 1000];
14+
15+
// Send last event then finish it.
16+
// [self sendEventWithName:@"rn-playback" body:@{
17+
// @"duration" : [duration stringValue],
18+
// @"current_position" : [duration stringValue],
19+
// @"justFinished" : @"1",
20+
// }
21+
// ];
22+
if (timer != nil) {
23+
[timer invalidate];
24+
timer = nil;
25+
}
26+
}
27+
28+
- (void)updateProgress:(NSTimer*) timer
29+
{
30+
NSLog(@"updateProgress");
31+
NSNumber *duration = [NSNumber numberWithDouble:audioPlayer.duration * 1000];
32+
NSNumber *currentTime = [NSNumber numberWithDouble:audioPlayer.currentTime * 1000];
33+
34+
NSDictionary *status = @{
35+
@"duration" : [duration stringValue],
36+
@"current_position" : [currentTime stringValue],
37+
};
38+
39+
// [self sendEventWithName:@"rn-playback" body:status];
40+
}
41+
42+
- (void)startTimer
43+
{
44+
// dispatch_async(dispatch_get_main_queue(), ^{
45+
// self->timer = [NSTimer scheduledTimerWithTimeInterval:1.0
46+
// target:self
47+
// selector:@selector(updateProgress:)
48+
// userInfo:nil
49+
// repeats:YES];
50+
// });
51+
}
52+
953

1054
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
1155
FlutterMethodChannel* channel = [FlutterMethodChannel
@@ -24,15 +68,17 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
2468
} else if ([@"stopRecorder" isEqualToString:call.method]) {
2569
[self stopRecorder:result];
2670
} else if ([@"startPlayer" isEqualToString:call.method]) {
27-
[self startPlayer:result];
71+
NSString* path = (NSString*)call.arguments[@"path"];
72+
[self startPlayer:path result:result];
2873
} else if ([@"stopPlayer" isEqualToString:call.method]) {
2974
[self stopPlayer:result];
3075
} else if ([@"pausePlayer" isEqualToString:call.method]) {
3176
[self pausePlayer:result];
3277
} else if ([@"resumePlayer" isEqualToString:call.method]) {
3378
[self resumePlayer:result];
3479
} else if ([@"seekToPlayer" isEqualToString:call.method]) {
35-
[self seekToPlayer:result];
80+
NSNumber* sec = (NSNumber*)call.arguments[@"sec"];
81+
[self seekToPlayer:sec result:result];
3682
} else {
3783
result(FlutterMethodNotImplemented);
3884
}
@@ -115,7 +161,6 @@ - (void)startPlayer:(NSString*)path result: (FlutterResult)result {
115161
}
116162

117163
if (!audioPlayer) {
118-
RCTLogInfo(@"audio player alloc");
119164
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileURL error:nil];
120165
audioPlayer.delegate = self;
121166
}
@@ -151,7 +196,6 @@ - (void)stopPlayer:(FlutterResult)result {
151196
}
152197

153198
- (void)pausePlayer:(FlutterResult)result {
154-
RCTLogInfo(@"pause");
155199
if (audioPlayer && [audioPlayer isPlaying]) {
156200
[audioPlayer pause];
157201
if (timer != nil) {
@@ -196,7 +240,7 @@ - (void)resumePlayer:(FlutterResult)result {
196240
- (void)seekToPlayer:(nonnull NSNumber*) time result: (FlutterResult)result {
197241
if (audioPlayer) {
198242
audioPlayer.currentTime = [time doubleValue];
199-
result(audioPlayer.currentTime);
243+
result(time);
200244
} else {
201245
result([FlutterError
202246
errorWithCode:@"Audio Player"

0 commit comments

Comments
 (0)