Reputation: 11
I have an app in which I am streaming a live TV channel in one of tabs. I am using MPMoviePlayerViewController
. I did declare my MPMoviePlayerViewController
in my header file and synthesize it in my implementation file.
Here's my viewDidAppear:
- (void)viewDidAppear:(BOOL)animated
{
NSURL *movieURL = [[NSURL alloc]initWithString:@"http://mysuperURL"];
moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self checkIt];
}
And my checkIt function
- (void) checkIt {
if ([[moviePlayerController moviePlayer] loadState] == MPMovieLoadStateUnknown) { // before you wreck yourself
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(checkIt) userInfo:nil repeats:NO];
} else {
[moviePlayerController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:moviePlayerController animated:YES];
}
}
However the video freezes after two seconds and the app stops responding.
Upvotes: 0
Views: 1306
Reputation: 27597
You should use the MPMoviePlayerNotifications instead of manually polling the current state.
For example - somewhere in you initializing code:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(MPMoviePlayerLoadStateDidChange:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
Now implement a notification handler:
- (void)MPMoviePlayerLoadStateDidChange:(NSNotification *)notification
{
NSLog(@"loadstate change: %Xh", movieController_.loadState);
}
And somewhere within your deinitializing code:
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
Also note that MPMoviePlayerController.loadState is a bitmap -> you need to mask out the value you want to check for.
For Example:
if ((movieController_.loadState & MPMovieLoadStatePlayable) == MPMovieLoadStatePlayable)
{
NSLog(@"yay, it became playable");
}
Upvotes: 2
Reputation: 5540
Asfar as my knowledge concern usage of timer it is freezing and it takes time streaming also.
Upvotes: 0