standard has error apple iphone objective-c xcode streaming

iphone - has - media streaming ios



¿Cómo obtener la duración de AVPlayer(no AVAudioPlayer)? (6)

A partir de iOS 4.3, puede utilizar el ligeramente más corto:

self.player.currentItem.duration;

Me gustaría crear un UISlider (depurador) para mi AVPlayer. Pero como este no es un AVAudioPlayer, no tiene una duración incorporada. ¿Alguna sugerencia sobre cómo crear el control deslizante para avanzar, rebobinar y avanzar la reproducción?

Leí el documento en AVPlayer, tiene una función incorporada en seekToTime o seekToTime: toleranceBefore: toleranceAfter :. Realmente no lo entiendo ¿Esta sería la respuesta para mi control deslizante? AVPlayer también tiene addPeriodicTimeObserverForInterval: queue: usingBlock :, ¿esto es para obtener la duración de mi pista? ¿Puede alguien darme un ejemplo sobre cómo implementar este código? No soy fanático de la documentación de Apple. Parece muy difícil de entender.


En este ejemplo, avPlayer es la instancia de AVPlayer.

Construí un control de video que usa lo siguiente:

para colocar el control deslizante use algo como esto para obtener el porcentaje de la cabeza lectora a través de la película, deberá disparar esta función repetidamente. Entonces ejecutaría la función como:

float scrubberBarLocation = (scrubberBgImageView.frame.size.width / 100.0f) * [self moviePercentage]; - (float)moviePercentage { CMTime t1 = [avPlayer currentTime]; CMTime t2 = avPlayer.currentItem.asset.duration; float myCurrentTime = CMTimeGetSeconds(t1); float myDuration = CMTimeGetSeconds(t2); float percent = (myCurrentTime / myDuration)*100.0f; return percent; }

Luego, para actualizar el video, haría algo como:

- (void)updateVideoPercent:(float)thisPercent { CMTime t2 = avPlayer.currentItem.asset.duration; float myDuration = CMTimeGetSeconds(t2); float result = myDuration * thisPercent /100.0f; //NSLog(@"this result = %f",result); // debug CMTime seekTime = CMTimeMake(result, 1); [avPlayer seekToTime:seekTime]; }


Tomado de StitchedStreamPlayer

Debes usar player.currentItem.duration

- (CMTime)playerItemDuration { AVPlayerItem *thePlayerItem = [player currentItem]; if (thePlayerItem.status == AVPlayerItemStatusReadyToPlay) { /* NOTE: Because of the dynamic nature of HTTP Live Streaming Media, the best practice for obtaining the duration of an AVPlayerItem object has changed in iOS 4.3. Prior to iOS 4.3, you would obtain the duration of a player item by fetching the value of the duration property of its associated AVAsset object. However, note that for HTTP Live Streaming Media the duration of a player item during any particular playback session may differ from the duration of its asset. For this reason a new key-value observable duration property has been defined on AVPlayerItem. See the AV Foundation Release Notes for iOS 4.3 for more information. */ return([playerItem duration]); } return(kCMTimeInvalid); }


Para que Swift obtenga la duración en segundos

if let duration = player.currentItem?.asset.duration { let seconds = CMTimeGetSeconds(duration) print(seconds) }


encabezados

#import <AVFoundation/AVPlayer.h> #import <AVFoundation/AVPlayerItem.h> #import <AVFoundation/AVAsset.h>

código

CMTime duration = self.player.currentItem.asset.duration; float seconds = CMTimeGetSeconds(duration); NSLog(@"duration: %.2f", seconds);

marcos

AVFoundation CoreMedia


self.player.currentItem.asset.duration

¡Lo tengo!