1

单击全屏按钮时,我在 UIWebView 中播放本地视频时遇到了一些问题。

这是一个 iPad 应用程序,当我转到包含视频的视图并单击播放按钮时,它会正常播放,我可以跳过和暂停/播放。但是当点击全屏时,它会将视频拉伸到全屏,播放一秒钟,全屏会消失,而不是在它的位置显示视频只是一个白框。我已经在运行 iOS 6 的 iPad 3rd Gen 和运行 iOS 6 的 iPad 模拟器上对此进行了测试,两者都做同样的事情。然而,在运行 iOS 5 的第一代 iPad 和运行 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 加载来自本地视频的视频标签。我在网上看得很清楚,但找不到任何关于此的内容。希望这只是简单的事情!

4

1 回答 1

0

好的,这就是我修复它的方法。

添加 MediaPlayer 框架。Target > Build Phases > Link Binary.. > + button < 开始输入 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 中为我工作

于 2013-03-08T17:56:14.710 回答