2011-05-17 15 views
15

iOS'ta bir Internet URL'sinden veya yerel bir dosyadan nasıl .mp4 veya .mov videosu çalarım? Her şeydeniOS'ta yerel veya sunucu URL'sinden bir video nasıl oynatılır

+1

olası yinelenen (http://stackoverflow.com/questions/5015165/playing-a-video-file-from-server-in-an-iphone-app) –

+0

http://stackoverflow.com/questions/5977330/play-video-by-default-in-full-screen/5977396#5977396 çoğaltması –

cevap

28

1.First

2.Then eklemek XCode

yılında MediaPlayer.Framework eklemek alma < MediaPlayer/MediaPlayer.h>

3.Now Bu kodu uygulamak için viewController en .h dosyasında senin Yönlendirmesi'ni viewDidLoad Yöntem

 //NSString *filepath = [[NSBundle mainBundle] pathForResource:@"aaa" ofType:@"mp4"]; 
    //NSURL *fileURL = [NSURL fileURLWithPath:filepath]; 

    NSURL *fileURL = [NSURL URLWithString:@"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"]; 

    moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; 
    [moviePlayerController.view setFrame:CGRectMake(0, 70, 320, 270)]; 
    [self.view addSubview:moviePlayerController.view]; 
    moviePlayerController.fullscreen = YES; 
    [moviePlayerController play]; 

Bu kodu

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    // Return YES for supported orientations 
      if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { 
     [moviePlayerController.view setFrame:CGRectMake(0, 70, 320, 270)]; 
    } else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) { 
     [moviePlayerController.view setFrame:CGRectMake(0, 0, 480, 320)]; 
    } 
    return YES; 
} 
ekleyiniz

Bu kod filmindePlayerController, .h dosyasında bildirilen MPMoviePlayerController dosyasıdır.

9

Bu eski bir sorudur, ancak yine de iOS 9, MPMoviePlayerController uygulamasını kullanımdan kaldırmıştır. -> izin ver Keyfi Loads-

NSString *filepath = [[NSBundle mainBundle] pathForResource:@"vid" ofType:@"mp4"]; 
NSURL *fileURL = [NSURL fileURLWithPath:filepath]; 
self.avPlayer = [AVPlayer playerWithURL:fileURL]; 

AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer]; 
self.avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone; 
layer.frame = self.view.bounds; 
[self.view.layer addSublayer: layer]; 

[self.avPlayer play]; 
3

bu onun mükemmel benim için

var moviePlayer:MPMoviePlayerController! 
override func viewDidLoad() 
{ 
    super.viewDidLoad() 

    let url:NSURL = NSURL(string: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")! 
    moviePlayer = MPMoviePlayerController(contentURL: url) 

    moviePlayer.view.frame = CGRect(x: 20, y: 20, width: UIScreen.mainScreen().bounds.size.width-40, height: UIScreen.mainScreen().bounds.size.height/2) 

    self.view.addSubview(moviePlayer.view) 
    moviePlayer.fullscreen = true 

    moviePlayer.controlStyle = MPMovieControlStyle.Embedded 

} 

çalışma Ve Uygulama Taşıma Güvenlik Ayarları etkinleştirin deneyin: yeni bir şey AVMoviePlayer eğer, örnek kodu kullanma -> Plist dosyasında YES. [Bir Iphone uygulamasında sunucudan bir video dosyasının çalınması] arasında

İlgili konular