audioplayer icon indicating copy to clipboard operation
audioplayer copied to clipboard

iOS - proper stop code

Open ozc opened this issue 6 years ago • 3 comments

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");
  }
}

ozc avatar Apr 15 '18 01:04 ozc

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

rxlabz avatar Apr 21 '18 13:04 rxlabz

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');

sridharmane avatar May 15 '18 16:05 sridharmane

@rxlabz was this already released?

letiagoalves avatar Dec 24 '18 16:12 letiagoalves