gpt4 book ai didi

iphone - 如何在 iPhone 中播放 URL 中的视频

转载 作者:行者123 更新时间:2023-12-03 20:23:31 31 4
gpt4 key购买 nike

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

-(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 的子类;

- (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 并将其导入到您的类中

关于iphone - 如何在 iPhone 中播放 URL 中的视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5401531/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com