如何将视频添加到应用程序
我正在尝试制作一个播放视频的应用程序,但遇到了问题。我听到声音但看不到视频。我真诚地尝试四处寻找解决方案,但所有提示似乎都不起作用。代码如下:
VideoTestViewController.m
#import "VideoTestViewController.h"
@implementation VideoTestViewController
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
NSString *moviePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"spitfiregrill_iPhone.m4v"];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
theMovie.controlStyle = MPMovieControlStyleDefault;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];
[theMovie play];
}
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
VideoTestViewController.h
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
@interface VideoTestViewController : UIViewController {
}
@end
I'm trying to make an app that plays a video, and I'm having problems. I hear the sound but see no video. I have sincerely tried looking around for a solution, but all the tips don't seem to work. Here's the code:
VideoTestViewController.m
#import "VideoTestViewController.h"
@implementation VideoTestViewController
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
NSString *moviePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"spitfiregrill_iPhone.m4v"];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
theMovie.controlStyle = MPMovieControlStyleDefault;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];
[theMovie play];
}
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
VideoTestViewController.h
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
@interface VideoTestViewController : UIViewController {
}
@end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
全屏模式下的视频 -
Video in full screen mode -
有点猜测 - 但这就是我要做的:
VideoTestViewController.h
VideoTestViewController.m
A bit of guesswork - but this is what I'd do:
VideoTestViewController.h
VideoTestViewController.m