如何从iPhone中的URL播放视频

如何从iPhone中的URL播放视频

本文介绍了如何从iPhone中的URL播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在url中有一个视频,单击按钮,我必须播放视频,为此,我使用了UIWebView来播放该视频,为此,我使用了以下代码:

I have a video at in url, In a button click I have to play a video, for this I used UIWebView to play this video, for this I used the following code:

-(void)viewDidLoad
{
   NSString *string = @"http://www.boxmusiq.com/ThiruvasakamVideo/VTS_01_2_converted.mp4";
   youtubeview = [[YouTubeView alloc] initWithStringAsURL:string frame:CGRectMake(0, 0, 320, 480)];
   NSLog(@"the url is: %@",string);
   [self.view addSubview:youtubeview];
}

并在YouTubeView.m中YouTubeView是UIWebView的子类;

and In YouTubeView.mYouTubeView is a subclass of UIWebView;

- (YouTubeView *)initWithStringAsURL:(NSString *)urlString frame:(CGRect)frame;
{
 if (self = [super init])
 {
               // Create webview with requested frame size
   self = [[UIWebView alloc] initWithFrame:frame];

               // HTML to embed YouTube video
   NSString *youTubeVideoHTML = @"<html><head>\
                         <body style=\"margin:0\">\
                         <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
                         width=\"%0.0f\" height=\"%0.0f\"></embed>\
                         </body></html>";

   // Populate HTML with the URL and requested frame size
   NSString *html = [NSString stringWithFormat:youTubeVideoHTML, urlString, frame.size.width, frame.size.height];

   // Load the html into the webview
   [self loadHTMLString:html baseURL:nil];
       }

 return self;

}

推荐答案

只需尝试以下代码

MPMoviePlayerController *theMoviPlayer;
NSURL *urlString=[NSURL URLWithString:@"http://www.boxmusiq.com/ThiruvasakamVideo/VTS_01_2_converted.mp4"];
theMoviPlayer = [[MPMoviePlayerController alloc] initWithContentURL:urlString];
theMoviPlayer.scalingMode = MPMovieScalingModeFill;
theMoviPlayer.view.frame = CGRectMake(0, 60, 320, 350);
[self.view addSubview:theMoviPlayer.view];
[self.theMoviPlayer play];

注意:添加Mediaplayer FrameKit并将其导入您的班级

Note: Add Mediaplayer FrameKit and import it into your class

这篇关于如何从iPhone中的URL播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 23:22