44

I am using AVPlayer in my chat application but i am getting the fallowing error in selected audio files but the audio files correctly play in browser.

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSUnderlyingError=0x60800024fde0 {Error Domain=NSOSStatusErrorDomain Code=-16170 "(null)"}, NSLocalizedFailureReason=An unknown error occurred (-16170), NSLocalizedDescription=The operation could not be completed}

I am implementing the following methods.

-(void)setupAVPlayerForURL:(NSURL*)url
 {
    AVAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
    AVPlayerItem *anItem = [AVPlayerItem playerItemWithAsset:asset];
    playerAud = nil;
    playerAud = [AVPlayer playerWithPlayerItem:anItem];
    [self startTimer];
    [playerAud play];
    [anItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopAudioPlay) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
}

And also implement the fallowing observer.

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    //// playerAud is instance of AVPlayer 
    if (object == playerAud.currentItem && [keyPath isEqualToString:@"status"]) {
        if (playerAud.currentItem.status == AVPlayerItemStatusFailed) {
            NSLog(@"------player item failed:%@",playerAud.currentItem.error);
        }
    }
}

It prints the above error.
CodeBender
  • 35,668
  • 12
  • 125
  • 132
Deepak Saki
  • 945
  • 1
  • 8
  • 16
  • try this http://stackoverflow.com/questions/4101380/avurlasset-refuses-to-load-video – Amod Gokhale Feb 20 '17 at 12:38
  • @thanks Amod Gokhale..but its not working fileURLWithPath add file keyword with the audio url. – Deepak Saki Feb 20 '17 at 12:39
  • It may have been a bug in a specific version of iOS. I remember seeing this but after updating the OS, the problem is gone. – Yuchen Jun 23 '17 at 19:32
  • If the file you want to play is in iCloud, you need to download it first. Similar problems occur with image files as well. – delibalta May 08 '22 at 06:26

1 Answers1

1

In my case, I use http url.Set NSAllowsArbitraryLoads to YES fix the error.

  • 3
    Hello and welcome to SO! Please read the [tour](https://stackoverflow.com/tour), and [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer) For example you can elaborate where are you using it, what effect does it have, and how it solves the question. – Tomer Shetah Dec 29 '20 at 09:38