MPMoviePlayerViewController没有播放视频。

时间:2017-03-21 05:51:17

标签: ios objective-c iphone mpmovieplayercontroller avplayerviewcontroller

我正在使用本地路由器播放视频。我已经配置了路由器和附加的pendrive与我的路由器。笔式驱动器有一些视频文件。我从路由器获取了一个URL(即http://192.168.0.1/user/root/Sample.mp4)。当我在网络浏览器上打开这个网址时,视频播放完全正常,但是当尝试使用MPMoviePlayerViewController或AVPlayerViewController播放相同的网址时,它无法正常工作。

我观察到一件有趣的事情,如果我在iphone浏览器上打开相同的网址就不会播放。

请帮助我或者让我知道为什么它不能在移动应用上播放。

2 个答案:

答案 0 :(得分:0)

moviePlayerController = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
 [player prepareToPlay];
player.movieSourceType = MPMovieSourceTypeStreaming;
[self presentMoviePlayerViewControllerAnimated:moviePlayerControll‌​er]; 
[moviePlayerController.moviePlayer play];
  

添加player.movi​​eSourceType = MPMovieSourceTypeStreaming;在你的代码中

被修改

@property (strong, nonatomic ) MPMoviePlayerController*player;

   NSURL *movieURL = [NSURL URLWithString:@"http://clips.vorwaerts-gmbh.de/VfE_html5.mp4"];

self.player  = [[MPMoviePlayerController alloc] initWithContentURL: movieURL];
[self.player prepareToPlay];
[self.player.view setFrame:CGRectMake(0, 0, 320, 320)];
[self presentMoviePlayerViewControllerAnimated:self.player];


self.player.fullscreen = YES;
self.player.controlStyle = MPMovieControlStyleDefault;
self.player.movieSourceType = MPMovieSourceTypeStreaming;
// player's frame must match parent's [self.view addSubview: self.movieController.view]; [self.movieController play];
[self.player play];
[self.view addSubview:self.player.view];

答案 1 :(得分:0)

我有玩视频的问题。我尝试了很多方法,但没有任何帮助。最后我使用下面的代码。现在工作正常。我使用iOS 10 。所以我使用不推荐使用AVPlayerViewController作为MPMoviePlayerViewController

ViewController.h

#import <UIKit/UIKit.h>
#import <AVKit/AVKit.h>
@interface ViewController : UIViewController
@property (strong, nonatomic) AVPlayerViewController *playerViewController;
- (IBAction)actionPlayVideo:(id)sender
@end

ViewController.m

#import "ViewController.h"

@interface ViewController (){
    NSURL *vedioURL;
}

@end

@implementation ViewController
@synthesize playerViewController;

- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)actionPlayVideo:(id)sender 
{
    vedioURL = @"192.168.0.1/user/root/Sample.mp4"; 
    AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:vedioURL];
    AVPlayer* playVideo = [[AVPlayer alloc] initWithPlayerItem:playerItem];
    playerViewController = [[AVPlayerViewController alloc] init];
    playerViewController.player = playVideo;
    playerViewController.player.volume = 0;
    playerViewController.view.frame = self.view.bounds;
    [self.view addSubview:playerViewController.view];
    [playVideo play];
}

请查看您的iPhone,iPad或iPod