最近在做一个在线播放的软件, 发现远程视频的播放与本地播放没什么区别, 都是得到一个NSURL.
下面是本地得到NSURL代码:
- - (id)initWithPath:(NSString *)moviePath
- {
- if (self = [super init])
- {
- movieURL = [NSURL fileURLWithPath:moviePath];
- [movieURL retain];
- }
- return self;
- }
下面是远程地址得到NSURL代码:
- - (id)initWithURL:(NSURL *)URL
- {
- if (self = [super init])
- {
- movieURL = URL;
- [movieURL retain];
- }
- return self;
- }
下面是播放视频代码:
- - (void)loadMoviePlayer
- {
- /*
- // Play movie from app bundle
- NSString *path = [[NSBundle mainBundle] pathForResource:@"Movie-1" ofType:@"mp4" inDirectory:nil];
- moviePlayer = [[[CustomMoviePlayerViewController alloc] initWithPath:path] autorelease];
- */
- // Play movie from URL
- NSURL *movieURL = [NSURL URLWithString:@"http://someurlsomewhere.com/movie.mp4"];
- moviePlayer = [[[CustomMoviePlayerViewController alloc] initWithURL:movieURL] autorelease];
- // Show the movie player as modal
- [self presentModalViewController:moviePlayer animated:YES];
- // Prep and play the movie
- [moviePlayer readyPlayer];
- }
是不是觉得很简单呀,其实iphone下的东西就是这么简单的,努力学习。