2

i want to play a video on the link: www.mysite.com/iphone/video.mp4

i use ios5 and MPMoviePlayerController i tried with the following code but it only shows a black page:

MPMoviePlayerController *player=[[MPMoviePlayerController alloc]initWithContentURL:[NSURL URLWithString:@"http://www.mysite.com/iphone/video.mp4"]];                                               [[player view] setFrame:[self.view.bounds]];                                                                                       [self.view addSubview:[player view]]; [player play]; 

is it possible to play a video by the web url string? i have many videos so i dont want to put them in my project so i need to play it from web

@Edit: I done it with the example on the apple's developer site

it uses stream but solves my problem because i use a web url. thanks for all answers

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
ercan
  • 825
  • 3
  • 16
  • 27
  • Check video exist or not on URL you are fetching from – Mangesh May 17 '12 at 13:11
  • i try with the url : http://www.ebookfrenzy.com/ios_book/movie/movie.mov but not playing – ercan May 17 '12 at 13:15
  • Hi ercan, have u got the solution b'cos i m facing same problem(unable to play video using web url).If u got answer then please share which is useful for us.Thanks – Priyanka Jun 15 '13 at 06:42

3 Answers3

0

try this

NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"3idiots.mov" ofType:nil];
    NSURL *url = [NSURL fileURLWithPath:urlStr];
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    [self.view addSubview:moviePlayer.view];
    moviePlayer.view.frame = CGRectMake(0, 0, 300, 400);  
    [moviePlayer play];
Rock
  • 1,408
  • 1
  • 12
  • 27
  • 1
    my problem is playing a mov or mp4 file from web url. my video is not inside of my project so i think the bundle is not my solution. but i try your code hopelessly it crashes and the error says: [NSURL initFileUrlWithPath:] : nil string parameter. i only change the pathForResource parameter from your code. – ercan May 17 '12 at 13:06
0

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

Writing an app to stream video to iPhone

Community
  • 1
  • 1
Mangesh
  • 2,257
  • 4
  • 24
  • 51
  • hi, we dont have streaming server so is it impossible to play a video from a link? we have only a simple windows hosting. – ercan May 17 '12 at 13:26
0

Remove

NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"3idiots.mov" ofType:nil];

Pass url like thislike this,

NSURL *videoURL = [NSURL URLWithString:@"http://www.youtube.com/v/HGd9qAfpZio&hl=en_US&fs=1&"];
Rock
  • 1,408
  • 1
  • 12
  • 27