Browse Source

修复本地播放问题

i2edu 4 years ago
parent
commit
64e73b6d74
2 changed files with 8 additions and 5 deletions
  1. 1 1
      example/.flutter-plugins-dependencies
  2. 7 4
      ios/Classes/FlutterSoundPlugin.m

+ 1 - 1
example/.flutter-plugins-dependencies

@@ -1 +1 @@
-{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"flutter_sound","dependencies":[]}]}
+{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_sound","path":"/Users/i2edu/Documents/workspace/flutter_sound/","dependencies":[]}],"android":[{"name":"flutter_sound","path":"/Users/i2edu/Documents/workspace/flutter_sound/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_sound","dependencies":[]}],"date_created":"2020-09-28 15:16:21.681463","version":"1.20.4"}

+ 7 - 4
ios/Classes/FlutterSoundPlugin.m

@@ -301,10 +301,13 @@ NSString* status = [NSString stringWithFormat:@"{\"current_position\": \"%@\"}",
 
     [downloadTask resume];
   } else {
-    // if (!audioPlayer) { // Fix sound distoring when playing recorded audio again.
-      audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileURL error:nil];
-      audioPlayer.delegate = self;
-    // }
+      NSData *imageData = [NSData dataWithContentsOfFile:path];
+          // if (!audioPlayer) { // Fix sound distoring when playing recorded audio again.
+      //      audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileURL error:nil];
+      //      audioPlayer.delegate = self;
+          // }
+    self->audioPlayer = [[AVAudioPlayer alloc] initWithData:imageData error:nil];
+    self->audioPlayer.delegate = self;
 
     // Able to play in silent mode
     [[AVAudioSession sharedInstance]