0

In my application i get the links of video from server in UITableview .all these link are store on Sever in Textfile,i get all these link from sever one by one and assign each to cell in UITableview.all these i done succefully but i want when i click on any cell in UITableview its play the video in next view.here is my code.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     nextview *dvController = [[nextview alloc] initWithNibName:@"nextview" bundle:nil];
     [self presentModalViewController:dvController animated:YES];
     strFile = [Listdata objectAtIndex:indexPath.row];
     NSLog(@"test=%@",strFile);
     [dvController release];
  }

and in next view i assign the link which i store in "strFile" to MPMoviePlayerController here is my code.

-(void)viewDidAppear:(BOOL)animated
 {
 NSLog(@"mytest=%@",strFile);
 NSURL *url = [NSURL URLWithString:strFile];
 NSLog(@"myurl=%@",url);
 myplayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
 myplayer.view.frame = CGRectMake(0, 0,900, 700);  
 [self.view addSubview:myplayer.view];
 [myplayer play];
 }

In NSlog i see the link but its not play in MPMoviePlayerController.Any one can guide me that what mistake i make.thanx in advance.

jamil
  • 2,419
  • 3
  • 37
  • 64

3 Answers3

2

@prince : can u tell me what url you are getting in NSLog?? i think u're mistaken in getting the url.

we can get url either by

url = [NSURL fileURLWithPath:strUrl];

else

url = [NSURL URLWithString:strUrl];

try it out once.

Mansi Panchal
  • 2,357
  • 18
  • 27
  • i see this url in NSlong test=http://www.youtube.com/watch?v=kJSkmmUhpHs mytest=http://www.youtube.com/watch?v=kJSkmmUhpHs myurl=http://www.youtube.com/watch?v=kJSkmmUhpHs – jamil Jun 06 '12 at 08:44
1

You probably shouldn't be setting the frame and adding to the subview, You may be confused with MPMoviePlayerViewController. Try this...

-(void)viewDidAppear:(BOOL)animated {
 NSLog(@"mytest=%@",strFile);
 NSURL *url = [NSURL URLWithString:strFile];
 NSLog(@"myurl=%@",url);
 myplayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
 myplayer.scalingMode = MPMovieScalingModeAspectFill;
 [myplayer play];
 }

EDIT disregard my code, you can't directly play a YouTube video in MPMoviePlayerController. Check this Post instead Play YouTube videos with MPMoviePlayerController instead of UIWebView

Community
  • 1
  • 1
skram
  • 5,314
  • 1
  • 22
  • 26
  • Dear skram i use your code nothing happen same result that no video play in my mpmovieplayer. – jamil Jun 06 '12 at 08:47
  • Thanx Ok i got your point but inside cell in uitableview i also have webview which show the thumbnail of that link which is store in that specific cell.can it possible to play video in nextview throught webview. – jamil Jun 06 '12 at 08:59
  • You can embed YouTube videos in a UIWebView, alternatively on the link that I posted there's an example doing so. – skram Jun 06 '12 at 09:04
0

to youtube video play inside app is to create a UIWebView with the embed tag from Youtube for the movie you want to play as the UIWebView's content. UIWebView will detect that the embedded object is a Youtube link, and the web view's content will be the youtube preview for the video. When your user clicks the preview, the video will be shown in an MPMoviePlayerController. try this link:

http://iphoneincubator.com/blog/audio-video/how-to-play-youtube-videos-within-an-application

Unfortunately, there's no way to directly play a youtube video with MPMoviePlayerController because youtube does not expose direct links to the video files.

kulss
  • 2,057
  • 1
  • 14
  • 16