在iOS中使用url播放嵌入视频

时间:2016-05-10 07:20:48

标签: ios

我已经在iOS中集成了放大器播放器,因此它可以播放精美的mp4视频,但我想在其中播放嵌入式视频。那我们怎么做呢?如果不能使用MPMoviePlayer,那么任何其他解决方案,请给kms。

由于

1 个答案:

答案 0 :(得分:0)

您可以使用MPMoviePlayerController播放mp4文件。像,

你的viewController.h文件

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>

@interface ViewController : UIViewController
{
AVAudioPlayer *audioPlayer;
MPMoviePlayerViewController *moviePlayer;

}
-(IBAction)playAudio:(id)sender;
-(IBAction)playVideo:(id)sender;
@end

你的viewController.m文件应该是,

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
 -(IBAction)playAudio:(id)sender{
 NSString *path = [[NSBundle mainBundle]
 pathForResource:@"audioTest" ofType:@"mp3"];
 audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:
 [NSURL fileURLWithPath:path] error:NULL];
 [audioPlayer play];
 }
 -(IBAction)playVideo:(id)sender{
  NSString *path = [[NSBundle mainBundle]pathForResource:
@"videoTest" ofType:@"mov"];
 moviePlayer = [[MPMoviePlayerViewController 
 alloc]initWithContentURL:[NSURL fileURLWithPath:path]];
 [self presentModalViewController:moviePlayer animated:NO];
 }
 @end

您可以参考this tutorial了解更多详情

希望这会有所帮助:)