问题
I've set up an instance on Amazon AWS running Flash Media Server (FMS), which is broadcasting Live HTTP Streaming (HLS) following these instructions, so I know I'm steaming using the right streaming format for iPhone.
Further, using the same instructions i've confirmed that the server is up and running and i've successfully set up a flash client to read its HDS stream (HTTP Dynamic Stream for flash devices).
I wrote this iphone client code to play the stream (stolen from a tutorial that makes it work with a local video file.. that worked for me too):
@implementation BigBuckBunnyViewController
-(IBAction)playMovie:(id)sender
{
NSURL *streamURL = [NSURL URLWithString:@"http://dstvrton8xbej.cloudfront.net/hls-live/livepkgr/_definst_/liveevent/livestream.m3u8"];
MPMoviePlayerController *moviePlayerContoller = [[MPMoviePlayerController alloc] initWithContentURL:streamURL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlaybackComplete) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerContoller];
[self.view addSubview:moviePlayerContoller.view];
moviePlayerContoller.fullscreen = YES;
[moviePlayerContoller play];
}
- (void)moviePlaybackComplete: (NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
}
but i get this error msg when i compile the code onto my ipad:
2012-07-13 17:45:20.513 BigBuckBunny[3714:607] -[BigBuckBunnyViewController moviePlaybackComplete]: unrecognized selector sent to instance 0x21050080
2012-07-13 17:45:20.524 BigBuckBunny[3714:607] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[BigBuckBunnyViewController moviePlaybackComplete]: unrecognized selector sent to instance 0x21050080'
from Mac documentation NSInvalidArgumentException happens when you pass an invalid argument to a method, such as a nil pointer where a non-nil object is required. Any ideas folks?
回答1:
The solution is simple.. basically it's a syntax error (lol).. add ':' after moviePlaybackComplete
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerContoller];
来源:https://stackoverflow.com/questions/11473381/trying-to-live-stream-from-aws-fms-to-iphone-using-hls