How to make avplayer in osx autoplay?
I've tried this:
NSURL *videoURL = [[NSBundle mainBundle]
URLForResource:@"video name" withExtension:@"mp4"];
self.movieView.player = [AVPlayer playerWithURL:videoURL];
it doesn't autoplay?
AVPlayer does not have a method named stop . You can pause or set rate to 0.0. Show activity on this post. I usually seekToTime 0.0, then pause.
Overview. A player is a controller object that manages the playback and timing of a media asset. Use an instance of AVPlayer to play local and remote file-based media, such as QuickTime movies and MP3 audio files, as well as audiovisual media served using HTTP Live Streaming.
And to track playing you can: "track changes in the position of the playhead in an AVPlayer object" by using addPeriodicTimeObserverForInterval:queue:usingBlock: or addBoundaryTimeObserverForTimes:queue:usingBlock:. You could throw in a Boolean flag to check the play status.
An AVPlayer is a controller object used to manage the playback and timing of a media asset. You can use an AVPlayer to play local and remote file-based media, such as QuickTime movies and MP3 audio files, as well as audiovisual media served using HTTP Live Streaming. AVPlayer is for playing a single media asset at a time.
Enable or Disable AutoPlay in Settings Open the “Settings” app, and click on the “Devices” icon. Click on “AutoPlay” on the left side, and switch on/off “Use AutoPlay for all media and devices.”
As a background video there should be no controls visible. Show activity on this post. You can add the property shouldPlay in your code, this will make the video autostart playing, then the app loads. Hope it solved the problem.
Experience the exhilaration of watching and controlling up to 16 Awesome Videos all at the same time on one screen! Go ahead, we know you’ll love it, especially with that exciting AV collection. ; ) Why Use AVPlayer Instead of Other Media Players? Because watching AV one at a time is just so boring!
You haven't called the play method.
[self.movieView.player play]
I think, AVplayer first check the URL content is available or not. You must add observer on it.
[avplayerObject addObserver:self forKeyPath:@"status" options:0 context:nil];
#pragma Observer for Player status.
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (object == _audioPlayer && [keyPath isEqualToString:@"status"]) {
if (_audioPlayer.status == AVPlayerStatusFailed) {
NSLog(@"AVPlayer Failed");
loader.hidden = true;
} else if (_audioPlayer.status == AVPlayerStatusReadyToPlay) {
NSLog(@"AVPlayerStatusReadyToPlay");
[_audioPlayer play];
} else if (_audioPlayer.status == AVPlayerItemStatusUnknown) {
NSLog(@"AVPlayer Unknown");
}
[_audioPlayer removeObserver:self forKeyPath:@"status" context:nil];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With