iPhone UIWebview video playback 4.0

2019-04-02 19:08发布

Now that 4.0 is public, I can edit this question and ask it again. This code works in 3.2 and any prior versions, but in 4.0 I get an alertView saying "This movie could not be played".

ivar webView

//in viewDidLoad
self.webView =  [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];

webView.scalesPageToFit = YES;
webView.delegate = self;

// in tableView didSelectRowAtIndexPath

// url contains a video from web 
NSURL *url = [NSURL URLWithString:@"http://www.somevalid.td/validmovie.mp4"];
[webView loadRequest:[NSURLRequest requestWithURL:url]];

In the log it says "setting movie path (null)"

2条回答
Evening l夕情丶
2楼-- · 2019-04-02 19:37

What I just did:

MPMoviePlayerViewController* theMoviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL: theURL];
[self presentMoviePlayerViewControllerAnimated:theMoviePlayer];

I know it's not a UIWebView, but it's the only way I got video working in OS 4.0..

Good luck though and I hope this was of any use.

Greetings,

Lewion

查看更多
迷人小祖宗
3楼-- · 2019-04-02 19:42

I just tested your code and it works fine on both simulator and on a development iPhone 3GS. Could it be something with the movie file itself (maybe too high resolution for iPhone?) or something with the server.

Try to download the NSURL to a file on your device, then use Organizer to copy it to your computer and in iTunes, copy it back and see if it plays. If not, you know that the problem lies with the movie file itself.

查看更多
登录 后发表回答