Search code examples
iosobjective-cmpmovieplayercontroller

How to play video in ios 6


I need playing a video in my app What I can do? thanks. *This is my code.*

#import <MediaPlayer/MediaPlayer.h>
 NSURL *fileURL = [NSURL URLWithString:@"http://nordenmovil.com/urrea/InstalaciondelavaboURREAbaja.mp4"];

       MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
        [moviePlayerController.view setFrame:CGRectMake(0, 0, 320, 270)];
        [self.view addSubview:moviePlayerController.view];
        moviePlayerController.fullscreen = YES;
        [moviePlayerController play];

Solution

  • Since you are trying to play a video from an URL, you can play it using WebView. Here is some sample code (Tested!):

     NSURL *fileURL = [NSURL URLWithString:@"http://nordenmovil.com/urrea/InstalaciondelavaboURREAbaja.mp4"];
    
    NSURLRequest* requestUrl = [[NSURLRequest alloc] initWithURL:fileURL];
    
    UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 640)];
    [self.view addSubview:webView];
    [webView loadRequest:requestUrl];