点击全屏按钮时,我在UIWebView中播放本地视频时遇到了一些问题。
这是一个iPad应用程序,当我转到包含视频的视图时,单击播放按钮它会播放正常,我可以跳过并暂停/播放。但是当点击全屏时,它会将视频拉伸到全屏,播放一秒钟,全屏将消失,而不是在其中显示视频的地方只是一个白色的框。我在运行iOS 6的iPad 3rd Gen和运行iOS 6的iPad模拟器上进行了测试,两者都是这样做的。然而,在运行iOS 5的iPad 1st Gen和运行iOS 5的模拟器上,两者都可以全屏播放。
在iOS 6 iPad /模拟器上,当我点击视频播放时,在调试区域中,我看到以下内容:
2012-12-06 16:11:07.361 PICO[19131:11f03] [MPAVController] Autoplay: Enabling autoplay
2012-12-06 16:11:07.362 PICO[19131:11f03] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
2012-12-06 16:11:07.362 PICO[19131:11f03] setting movie path: file:///Users/Nathan/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/DB4C3A91-F148-417B-8319-4690F89E1382/PICO.app/30.20.mp4
2012-12-06 16:11:07.362 PICO[19131:11f03] [MPAVController] Autoplay: Enabling autoplay
2012-12-06 16:11:07.368 PICO[19131:11f03] [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0
2012-12-06 16:11:07.437 PICO[19131:11f03] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
2012-12-06 16:11:07.447 PICO[19131:11f03] [MPAVController] Autoplay: Enabling autoplay
2012-12-06 16:11:07.448 PICO[19131:11f03] [MPAVController] Autoplay: _streamLikelyToKeepUp: 0 -> 1
然后当我点击全屏按钮时:
2012-12-06 16:12:39.918 PICO[19131:11f03] [MPAVController] Autoplay: Enabling autoplay
2012-12-06 16:12:40.168 PICO[19131:11f03] [MPAVController] Autoplay: Enabling autoplay
2012-12-06 16:12:40.178 PICO[19131:11f03] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 0, on player: 1)
无论如何,这是我的代码:
·H
@property (strong, nonatomic) IBOutlet UIWebView *videoView;
的.m
[videoView loadHTMLString:@"<body style=\"margin:0px;\"><video src=\"30.20.mp4\" controls width=\"640\" height=\"360\"></video></body>" baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]bundlePath]]];
videoView.scrollView.scrollEnabled = NO;
因此,您可以看到我只是使用loadHTMLString加载源自本地视频的视频标记。我在网上看了很多,但是找不到任何关于此事的信息。希望它只是简单的事情!
答案 0 :(得分:0)
好的,这是我修复它的方式。
添加MediaPlayer框架。目标&gt;构建阶段&gt;链接二进制..&gt; +按钮&lt;开始输入MediaPlayer
然后使用以下代码。
YourClass.h
#import <MediaPlayer/MediaPlayer.h>
@interface YourClass : UIViewController
@property (strong, nonatomic) MPMoviePlayerController *moviePlayer; //creating the property is a must else it will show a black box instead of your video and will not play
YourClass.m
@synthesize moviePlayer;
NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"myVideoFile" ofType:@"mp4"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
moviePlayer.view.frame = CGRectMake(73, 203, 640, 360); //position you want the player and it's size
[self.view addSubview:moviePlayer.view];
[moviePlayer prepareToPlay];
[moviePlayer setShouldAutoplay:NO]; //autoplays by default
适用于iOS 5.1和6