diff --git a/audio/out/ao_avfoundation.m b/audio/out/ao_avfoundation.m index 7a3f78c99e..19893ee45f 100644 --- a/audio/out/ao_avfoundation.m +++ b/audio/out/ao_avfoundation.m @@ -76,11 +76,14 @@ static void feed(struct ao *ao) int64_t cur_time_mp = mp_time_ns(); int64_t end_time_av = MPMAX(p->end_time_av, cur_time_av); int64_t time_delta = CMTimeGetNanoseconds(CMTimeMake(request_sample_count, samplerate)); - int real_sample_count = ao_read_data(ao, data, request_sample_count, end_time_av - cur_time_av + cur_time_mp + time_delta, NULL, false, false); + bool eof; + int real_sample_count = ao_read_data(ao, data, request_sample_count, end_time_av - cur_time_av + cur_time_mp + time_delta, &eof, false, false); + if (eof) { + [p->renderer stopRequestingMediaData]; + ao_stop_streaming(ao); + } if (real_sample_count == 0) { - // avoid spinning by blocking the thread - mp_sleep_ns(10000000); - goto finish; + return; } if ((err = CMBlockBufferCreateWithMemoryBlock(