Coder Social home page Coder Social logo

Comments (4)

AlvaroFranco avatar AlvaroFranco commented on June 13, 2024

Sounds weird. I'm currently kind of busy with my final exams, but I will look into it as soon as I finish. Stay tuned!

from afsoundmanager.

AlvaroFranco avatar AlvaroFranco commented on June 13, 2024

Even with slow connection I haven't been able to reproduce that bug, the completion block keeps being called till the playing stops

from afsoundmanager.

brunogama avatar brunogama commented on June 13, 2024

i've solved the problem doing this

            if ((_audioPlayer.duration - _audioPlayer.currentTime) >= 1 ||
                [_player status] != AVPlayerStatusFailed)

not tested enought.

doesn't work.

from afsoundmanager.

brunogama avatar brunogama commented on June 13, 2024
-(void)startStreamingRemoteAudioFromURL:(NSString *)url andBlock:(progressBlock)block {

    NSURL *streamingURL = [NSURL URLWithString:url];
    NSError *error = nil;

    _player = [[AVPlayer alloc]initWithURL:streamingURL];
    [_player play];

    _status = AFSoundManagerStatusPlaying;
    [_delegate currentPlayingStatusChanged:AFSoundManagerStatusPlaying];

    if (!error) {

        __block int percentage = 0;

        _timer = [NSTimer scheduledTimerWithTimeInterval:1 block:^{
#ifdef DEBUG
            NSLog(@"player status %i", [_player status]);
            NSLog(@"currenTime %d", _audioPlayer.currentTime);
            NSLog(@"duration %i", _audioPlayer.duration);
#endif
            if ([_player status] == AVPlayerStatusUnknown || _audioPlayer.currentTime == 79609804) {
                return;
            }

            percentage = (int)((CMTimeGetSeconds(_player.currentItem.currentTime) * 100)/CMTimeGetSeconds(_player.currentItem.duration));

            if (percentage != 100) {

                int timeRemaining = CMTimeGetSeconds(_player.currentItem.duration) - CMTimeGetSeconds(_player.currentItem.currentTime);

                if (block) {
                    block(percentage, CMTimeGetSeconds(_player.currentItem.currentTime), timeRemaining, error, NO);
                }
            } else {

                int timeRemaining = CMTimeGetSeconds(_player.currentItem.duration) - CMTimeGetSeconds(_player.currentItem.currentTime);

                if (block) {
                    block(100, CMTimeGetSeconds(_player.currentItem.currentTime), timeRemaining, error, YES);
                }
                [_timer invalidate];
                _status = AFSoundManagerStatusFinished;
                [_delegate currentPlayingStatusChanged:AFSoundManagerStatusFinished];
            }
        } repeats:YES];
    } else {

        if (block) {
            block(0, 0, 0, error, YES);
        }
        [_audioPlayer stop];
    }
}

this works.

from afsoundmanager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.