Writing an app to stream video to iPhone

后端 未结 6 732
北海茫月
北海茫月 2020-12-04 10:25

I\'m interested in creating an iPhone app that can stream video from a central server, YouTube style. I was wondering if anyone has ever tried to do this before, what is the

相关标签:
6条回答
  • 2020-12-04 10:58

    If you have the streaming server up and ready, it is quite easy to implement a video controller that pops up youtube-style.

    NSString *videoURLString = @"http://path-to-iphone-compliant-video-stream";
    NSURL *videoURL = [NSURL URLWithString:videoURLString];
    MPMoviePlayerController moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL]; 
    [moviePlayer prepareToPlay]; 
    [moviePlayer play];
    [self.view addSubview:moviePlayer.view];
    

    You need to handle the controller that display the video player's view (which is self in this case).

    In iOS 3.2+ MPMoviePlayerViewController make it even easier:

    NSString *videoURLString = @"http://path-to-iphone-compliant-video-stream";
    NSURL *videoURL = [NSURL URLWithString:videoURLString];
    MPMoviePlayerViewController *moviePlayerView = [[[MPMoviePlayerViewController alloc] initWithContentURL:videoURL] autorelease];
    [self presentMoviePlayerViewControllerAnimated:moviePlayerView];
    

    presentMoviePlayerViewControllerAnimated is a MediaPlayer's additional method to FWViewController that you will find in iOS 3.2+ and it takes care of creating a view controller and pushing it on the stack, animating it with a slide-from-bottom animation, as in youtube.app.

    0 讨论(0)
  • 2020-12-04 10:58

    Use this code to use low memory. On streaming video....

    -(IBAction)playMovie:(NSURL *) theURL 
    {
        NSURL    *fileURL    =   theURL;
        MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
    
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(moviePlaybackComplete:)
                                                     name:MPMoviePlayerPlaybackDidFinishNotification
                                                   object:moviePlayerController];
    
        [self.view addSubview:moviePlayerController.view];
        moviePlayerController.useApplicationAudioSession = NO;
        moviePlayerController.fullscreen = YES;
        [moviePlayerController play];
    }
    
    - (void)moviePlaybackComplete:(NSNotification *)notification
    {
        MPMoviePlayerController *moviePlayerController = [notification object];
        [[NSNotificationCenter defaultCenter] removeObserver:self
                                                        name:MPMoviePlayerPlaybackDidFinishNotification
                                                      object:moviePlayerController];
    
        [moviePlayerController.view removeFromSuperview];
        [moviePlayerController release];
    }
    
    0 讨论(0)
  • 2020-12-04 11:03

    While the existing answers are good, if you need to use non HTTP streams (mms or rtmp for example) or non Apple supported audio / video codecs, things get a bit more complicated.

    I'm not an expert myself, but I've been using this VideoStreaming SDK to solve those problems, and it makes customizing the client much easier (background streaming, pausing streams, etc). Might be worth a look if you have those requirements as well.

    0 讨论(0)
  • 2020-12-04 11:13

    Apple has a detailed article about setting up server side for media streaming:

    https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/StreamingMediaGuide/Introduction/Introduction.html

    and Best Practices Note:

    https://developer.apple.com/library/content/technotes/tn2224/_index.html

    Not only it contains info about streaming service architecture and tools used to build it but also has some requirements to such kind of service that must be fulfilled and references to live test streams.

    0 讨论(0)
  • 2020-12-04 11:13

    QuickTime videos already stream to the phone. The path of least resistance would be to use the media player controller and point it to a streaming media file on a streaming server.

    0 讨论(0)
  • 2020-12-04 11:14

    2018 answer You can use AVPlayerViewController since MPMoviePlayerController is deprecated since iOS 9

        NSURL *url = [NSURL URLWithString:videoUrl];
    
        _playerViewController = [[AVPlayerViewController alloc] init];
        _playerViewController.player = [AVPlayer playerWithURL:url];
        _playerViewController.player.volume = 1;
        _playerViewController.showsPlaybackControls = YES;
    
        _playerViewController.view.frame = CGRectMake(....);
        [self.view addSubview:_playerViewController.view];
    
    0 讨论(0)
提交回复
热议问题