AVPlayer Element erhalten Sie ein nan Dauer

Ich bin die Wiedergabe einer Datei. mp3 von url vom stream.
Ich bin mit AVPlayer und wenn ich versuche die gesamte Zeit für den Aufbau einer Statusleiste, die ich bekomme, Wann immer Zeit ist nan.

 NSError *setCategoryError = nil;
    if ([ [AVAudioSession sharedInstance] isOtherAudioPlaying]) { //mix sound effects with music already playing
        [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategorySoloAmbient error:&setCategoryError];
    } else {
        [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error:&setCategoryError];
    }
    if (setCategoryError) {
        NSLog(@"Error setting category! %ld", (long)[setCategoryError code]);
    }
    NSURL *url = [NSURL URLWithString:@"http://..//46698"];

    AVPlayer *player = [AVPlayer playerWithURL:url];
    songPlayer=player;
    [songPlayer addObserver:self forKeyPath:@"status" options:0 context:nil];



- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {

    if (object == songPlayer && [keyPath isEqualToString:@"status"]) {
        if (songPlayer.status == AVPlayerStatusFailed) {
            NSLog(@"AVPlayer Failed");

        } else if (songPlayer.status == AVPlayerStatusReadyToPlay) {
            NSLog(@"AVPlayerStatusReadyToPlay");
            [songPlayer play];
            [songPlayer addPeriodicTimeObserverForInterval:CMTimeMake(1, 1) queue:dispatch_get_main_queue() usingBlock:^(CMTime time){
                CMTime aux = [songPlayer currentTime];
                AVPlayerItem *item=[songPlayer currentItem];
                CMTime dur=[item duration];
                NSLog(@"%f/%f", CMTimeGetSeconds(aux),  CMTimeGetSeconds(dur));
            }];
        } else if (songPlayer.status == AVPlayerItemStatusUnknown) {
            NSLog(@"AVPlayer Unknown");

        }
    }
}

Habe ich schon alles ausprobiert.

[item duration]; ///Fail

[[item asset] duration]; ///Fail

und nichts arbeiten

Jemand wissen, warum?

  • ich bin auch mit dem gleichen Problem . hast du es herauszufinden, für diese ? wie haben Sie es tun ? auch ich habe alles versucht . so helfen Sie mir mit diesem Problem .
  • Ich habe auch das gleiche Problem. Hast du die Lösung finden? Bitte teilen Sie es uns mit.
InformationsquelleAutor Pedro | 2014-05-26
Schreibe einen Kommentar