在 iPhone 中播放视频网址

发布于 2025-01-03 23:22:44 字数 1188 浏览 3 评论 0原文

如何在 Iphone 中播放服务器 URL 视频? 如何使用 MPMoviePlayer 播放 url 中的视频?

 (void)loadVideo {

     videoUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://movies.apple.com/media/us/mac/getamac/2009/apple-mvp-biohazard_suit-us-20090419_480x272.mov"]];
       if(videoUrl) {

        if([videoUrl scheme]) {

            [self playVideoStream:videoUrl];
        }
    }
}

-(void)playVideoStream:(NSURL *)movieFileURL {

MPMovieSourceType movieSourceType = MPMovieSourceTypeUnknown;
/* If we have a streaming url then specify the movie source type. */
if ([[movieFileURL pathExtension] compare:@"mov" options:NSCaseInsensitiveSearch] == NSOrderedSame) 
{
    movieSourceType = MPMovieSourceTypeStreaming;
}
[self createAndPlayMovieForURL:movieFileURL sourceType:movieSourceType]; 
}

-(void)createAndPlayMovieForURL:(NSURL *)movieURL sourceType:(MPMovieSourceType)sourceType {

/* Play the video! */    
[moviePlayer setMovieSourceType:sourceType];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];;
moviePlayer.view.frame = CGRectMake(10, 20, 280, 210);  
[customVideoView addSubview:moviePlayer.view];
[moviePlayer play];
}

How To play Server URL Video in Iphone ?
how to play video from url using MPMoviePlayer ?

 (void)loadVideo {

     videoUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://movies.apple.com/media/us/mac/getamac/2009/apple-mvp-biohazard_suit-us-20090419_480x272.mov"]];
       if(videoUrl) {

        if([videoUrl scheme]) {

            [self playVideoStream:videoUrl];
        }
    }
}

-(void)playVideoStream:(NSURL *)movieFileURL {

MPMovieSourceType movieSourceType = MPMovieSourceTypeUnknown;
/* If we have a streaming url then specify the movie source type. */
if ([[movieFileURL pathExtension] compare:@"mov" options:NSCaseInsensitiveSearch] == NSOrderedSame) 
{
    movieSourceType = MPMovieSourceTypeStreaming;
}
[self createAndPlayMovieForURL:movieFileURL sourceType:movieSourceType]; 
}

-(void)createAndPlayMovieForURL:(NSURL *)movieURL sourceType:(MPMovieSourceType)sourceType {

/* Play the video! */    
[moviePlayer setMovieSourceType:sourceType];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];;
moviePlayer.view.frame = CGRectMake(10, 20, 280, 210);  
[customVideoView addSubview:moviePlayer.view];
[moviePlayer play];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

掩于岁月 2025-01-10 23:22:44

您需要首先设置 contentURL 属性

moviePlayer.contentURL = urlVideo;

[moviePlayer prepareToPlay];
[moviePlayer play];

You need to set contentURL property at fisrt

moviePlayer.contentURL = urlVideo;

[moviePlayer prepareToPlay];
[moviePlayer play];
走过海棠暮 2025-01-10 23:22:44

试试这个:

  {

      NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"//name of your video here" ofType:@"//format e.g. mp4, m4v"]];
MPMoviePlayerViewController *playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playerController];

playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

[playerController.moviePlayer play];


// When movie finished loading you can have a notification and do extra code
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MovieDidLoad:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];



[playerController release];

playerController = nil;
  }


  -(void)MovieDidLoad:(NSNotification *)notification {

  NSLog(@"logged and notification is %@", notification);

 // extra code if needed


   }

try this:

  {

      NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"//name of your video here" ofType:@"//format e.g. mp4, m4v"]];
MPMoviePlayerViewController *playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playerController];

playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

[playerController.moviePlayer play];


// When movie finished loading you can have a notification and do extra code
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MovieDidLoad:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];



[playerController release];

playerController = nil;
  }


  -(void)MovieDidLoad:(NSNotification *)notification {

  NSLog(@"logged and notification is %@", notification);

 // extra code if needed


   }
放血 2025-01-10 23:22:44

一种简单的方法是将视频 URL 加载到 UIWebview 中。

One of the easy way is to load that video url into a UIWebview.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文