Iphone 如何将视频添加到应用程序
我正在尝试制作一个播放视频的应用程序,但我遇到了一些问题。我听到声音,但看不到视频。我诚恳地四处寻找解决方案,但所有的提示似乎都不起作用。代码如下: VideoTestViewController.mIphone 如何将视频添加到应用程序,iphone,video,Iphone,Video,我正在尝试制作一个播放视频的应用程序,但我遇到了一些问题。我听到声音,但看不到视频。我诚恳地四处寻找解决方案,但所有的提示似乎都不起作用。代码如下: VideoTestViewController.m VideoTestViewController.h #import <UIKit/UIKit.h> #import <MediaPlayer/MediaPlayer.h> @interface VideoTestViewController : UIViewContro
VideoTestViewController.h
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
@interface VideoTestViewController : UIViewController {
}
@end
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
@interface VideoTestViewController : UIViewController
{
MPMoviePlayerController* m_player;
}
- (void) play;
@end
#导入
#进口
@接口VideoTestViewController:UIViewController{
}
@结束
有点猜测-但这就是我要做的:
VideoTestViewController.h
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
@interface VideoTestViewController : UIViewController {
}
@end
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
@interface VideoTestViewController : UIViewController
{
MPMoviePlayerController* m_player;
}
- (void) play;
@end
#进口
#进口
@接口VideoTestViewController:UIViewController
{
MPMoviePlayerController*m_播放器;
}
-(无效)游戏;
@结束
VideoTestViewController.m
@implementation VideoTestViewController
- (void) viewDidAppear:(BOOL)animated
{
[self play];
}
- (void) play
{
NSURL* url = [[NSBundle mainBundle] URLForResource:@"spitfiregrill_iPhone" withExtension:@"m4v"];
m_player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[m_player.backgroundView setBackgroundColor:[UIColor blackColor]];
[m_player.view setBackgroundColor:[UIColor blackColor]];
[m_player setControlStyle:MPMovieControlStyleNone];
[[m_player view] setFrame:[self.view bounds]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[m_player play];
[self.view addSubview:[m_player view]];
}
- (void) moviePlayBackDidFinish:(NSNotification*)_notification
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[m_player.view removeFromSuperview];
[m_player stop];
[m_player release];
m_player = nil;
}
@end
@VideoTestViewController的实现
-(无效)视图显示:(BOOL)动画
{
[自我游戏];
}
-(无效)玩
{
NSURL*url=[[NSBundle mainBundle]URLForResource:@“spitfiregrill_iPhone”及其扩展名:@“m4v”];
m_player=[[MPMoviePlayerController alloc]initWithContentURL:url];
[m_player.backgroundView setBackgroundColor:[UIColor blackColor]];
[m_player.view setBackgroundColor:[UIColor blackColor]];
[m_player setControlStyle:MPMovieControlStyleNone];
[[m_player view]setFrame:[self.view bounds];
[[NSNotificationCenter defaultCenter]添加观察者:自选择器:@selector(moviePlayBackDidFinish:)名称:MPMoviePlayerPlaybackDidFinishNotification对象:nil];
[m_player play];
[self.view addSubview:[m_player view]];
}
-(无效)电影回放完成:(NSNotification*)\u通知
{
[[NSNotificationCenter defaultCenter]移除观察者:self
名称:MPMoviePlayerPlaybackDidFinishNotification
对象:无];
[m_player.view从SuperView移除];
[m_player stop];
[m_播放器释放];
m_player=零;
}
@结束
全屏模式下的视频-
- (void)viewDidLoad {
NSString *url = [[NSBundle mainBundle]
pathForResource:@"Stock_Footage_Demobroadband"
ofType:@"mp4"];
MPMoviePlayerViewController *playerViewController =
[[MPMoviePlayerViewController alloc]
initWithContentURL:[NSURL fileURLWithPath:url]];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[playerViewController moviePlayer]];
[self.view addSubview:playerViewController.view];
//---play movie---
MPMoviePlayerController *player = [playerViewController moviePlayer];
[player play];
[super viewDidLoad];
}
- (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player stop];
[self.view removeFromSuperView];
[player autorelease];
}
欢迎来到stackoverflow!如果答案有效,你应该接受。。。帮助访问者了解这个答案是有效的!