Play MPMoviePlayerController synchronously with AVAudioPlayer

I am trying to add a movie to the entry into the game. There is no sound / music in the film. However, I do have a music loop in the background. Music is somewhat specific in that the entry into the music as long as the film, and then the pace is a little faster.

The problem I am facing is that on some devices, such as iPod 4G, music plays too fast, which ultimately disrupts the video sequence. This does not happen on my iPhone 4S.

I tried to find some kind of notice about when the movie started playing, and then started the music. I have not been successful.

Here is what I got so far:

-(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"SplashVideo" ofType:@"mp4"]]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:player]; [[player view] setFrame:CGRectMake(0, 0, 480, 320)]; [player setControlStyle:MPMovieControlStyleNone]; [[self view] addSubview:[player view]]; // play movie [player play]; //musicPlayer is defined in the header [self setMusicPlayer:[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"SplashMusic" ofType:@"m4a"]] error:nil]]; [[self musicPlayer] setNumberOfLoops:loop]; [[self musicPlayer] prepareToPlay]; [[self musicPlayer] setDelegate:self]; } - (void)moviePlayerPlaybackDidFinish:(NSNotification*) aNotification { DLog(@"**********"); MPMoviePlayerController *player = [aNotification object]; [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player]; [player stop]; [[player view] removeFromSuperview]; [player autorelease]; } 

In summary , it works flawlessly on the iPhone 4S, but on iPod 4G, music starts about 2 seconds before the movie does, which ends up throwing input. What can I do to make movie and music play synchronously?

Things I can't do unless otherwise stated:

  • I canโ€™t put music in the video, because the music is designed to scroll through several types.
  • I cannot create a movie in a UIImageView animation.
+4
source share
1 answer

Here is what I did if someone comes across this.

I created a notification for: MPMoviePlayerLoadStateDidChangeNotification

When the selector was called to return an MPMovieLoadStatePlaythroughOK notification, I played the movie and soundtrack.

Hope this helps.

+2
source

Source: https://habr.com/ru/post/1394732/


All Articles