【问题标题】:Play video from cache in iphone programmatically以编程方式从 iphone 的缓存中播放视频
【发布时间】:2011-11-16 04:26:01
【问题描述】:

我正在开发一个 iPhone 应用程序,我将在其中将来自 URL 的流视频直接存储到本地缓存中,现在我需要在电影播放器​​中播放视频,同时它正在缓存中下载。我关注了这个http://lists.apple.com/archives/cocoa-dev/2011/Jun/msg00844.html,但我不能准确。我可以在缓存中下载视频,但无法从缓存中播放视频。那么如何在下载的同时播放呢?

【问题讨论】:

  • 缓存意味着将视频保存到本地?
  • 您是说苹果列表中提供的源代码不起作用?好吧,无论如何-您正在尝试的似乎是自制的渐进式下载。对我来说,在任何情况下,这似乎都不聪明。我总是建议使用 HTTP 流。
  • 你有没有为你尝试做的这件事找到任何解决方案?
  • 你找到解决办法了吗?

标签: iphone caching mpmovieplayercontroller mpmovieplayer


【解决方案1】:

只需将您的 web url 更改为本地路径 url...

试试这个代码...

NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"Movie" ofType:@"m4v"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];

【讨论】:

    【解决方案2】:

    如果你使用弧 添加 .h 文件

    @property (nonatomic, strong) MPMoviePlayerController *controller;
    

    看看最后一行。祝你好运

    NSString *filepath   =   [[NSBundle mainBundle] pathForResource:@"Man of Steel" ofType:@"mp4"];
    NSURL    *fileURL    =   [NSURL fileURLWithPath:filepath];
    MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
    selector:@selector(moviePlaybackComplete:)
    name:MPMoviePlayerPlaybackDidFinishNotification
    object:moviePlayerController];
    
    [moviePlayerController.view setFrame:CGRectMake(0,0,500,500)];
    
    [self.view addSubview:moviePlayerController.view];
    //moviePlayerController.fullscreen = YES;
    
    //moviePlayerController.scalingMode = MPMovieScalingModeFill;
    
    [moviePlayerController play];
    
    [self setController:moviePlayerController];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-20
      • 2014-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多