rxlabz / audioplayer

A flutter plugin to play audio files iOS / Android / MacOS / Web ( Swift/Java )

Home Page:https://pub.dartlang.org/packages/audioplayer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

iOS - proper stop code

ozc opened this issue · comments

commented

Stop method was just pausing and moving the pointer back to the beginning. On streaming media this was leading to an issue of playing from the beginning of the cached part.

I think this should be a better replacement

-(void) stop {
  if(isPlaying){
    //[ self pause ];
    //[ self seek: CMTimeMake(0, 1) ];
    
    [player replaceCurrentItemWithPlayerItem: nil];

    lastUrl = nil; // In case play the same url/file again, AVPlayerItem needs to be recreated.
    isPlaying = false;
    NSLog(@"stop");
  }
}

thanks, it makes sense. I'm working on an update, I'll put this in !

As a work around till this is released, I created temp local files in a temp directory with each file having a unique name. Then during each new load, I clear the directory:

    Directory tempAudioDir = new Directory('${dir.path}/audio');
    if (await tempAudioDir.exists() && await tempAudioDir.list().length > 0) {
      print('Directory already exists, deleting contents recursively');
      List<FileSystemEntity> files = await tempAudioDir.list().toList();
      files.forEach((file) async {
        print('Deleting file at path: ${file.path}');
        await file.delete();
      });
    } else {
      print('Creating empty temp directory');
      tempAudioDir.create();
    }

    // Add Timestamp to file so a new file is created ever time
    // and so it doesnot get cached.
    File tempFile = new File(
        '${tempAudioDir.path}/audio-{${new DateTime.now().millisecondsSinceEpoch}.mp3');

@rxlabz was this already released?