14

Running into a weird issue while updating my app for iOS 7. For iOS 6, there is no problem and the videos are always loaded. However that is not the case here.

I have a scrollview which displays playlistItems - and once you click on the playlistItem, a MPMoviePlayerController is created to show the playlist item (video).

Here is the method that I believe is causing issues:

- (void) play:(NSInteger)itemId withAutostart:(BOOL)autostart {

  // remember whether it is in fullscreen or not to restore for the next playlist item
  self.playerInFullscreen = self.player.isFullscreen;

  if (player != nil) {
    [self.player setFullscreen:NO animated:NO];
    [self stopListeningPlaybackFinishedEvents];
    [player stop];
    [self startListeningPlaybackFinishedEvents];
  }

  PlaylistItem * pi = [dbHelper getPlaylistItem:itemId];
  NSURL *movieURL = [pi getMovieUrl];

  if (DELEGATE.useSSL) {

    NSURLCredential *credential = [[NSURLCredential alloc]
                                 initWithUser: DELEGATE.username
                                 password: DELEGATE.password
                                 persistence: NSURLCredentialPersistenceForSession];

    NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
                                           initWithHost: [movieURL host]
                                           port: 80
                                           protocol: [movieURL scheme]
                                           realm: [movieURL host]
                                           authenticationMethod: NSURLAuthenticationMethodHTTPBasic];

    [[NSURLCredentialStorage sharedCredentialStorage]
     setDefaultCredential: credential
     forProtectionSpace: protectionSpace];

    [protectionSpace release];
    [credential release];
  }


  MPMoviePlayerController * temp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    [temp prepareToPlay];

  self.player =  temp;
  [temp release];

    player.shouldAutoplay = autostart;
  player.view.frame = movieViewContainer.bounds; 
  [movieViewContainer addSubview:player.view];

    NSLog(@"movie added to subview");

  [player setFullscreen:self.playerInFullscreen animated:NO];
  [self.view setNeedsDisplay];
}

The movie is getting loaded to the MovieContainerView.

- (void)playlistItemSelected:(NSInteger)itemId withAutostart:(BOOL) autostart {
  for(UIView *subview in [thumbsScrollView subviews]) {
    if ([subview isKindOfClass:[PlaylistItemView class]] == YES ) {

      PlaylistItemView *piv = ((PlaylistItemView *) subview);
      [piv setCurrent: piv.playlistItem._id == itemId];

      if (piv.playlistItem._id == itemId) {
        [self ensurePlaylistItemViewVisible:piv];
      }
    }
  }
  [[movieViewContainer subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
  self.currentPlaylistItem = [dbHelper getPlaylistItem:itemId];
  [self updateMetadataArea:itemId];

  if ([_currentPlaylistItem.type isEqual:VIDEO_TYPE]) {
    self.zoomButtonOut.hidden = YES;
    self.zoomButtonIn.hidden  = YES;

    [self play:itemId withAutostart:autostart];
  }
  else {
     [self.player pause];
    _zoomButtonIn.alpha = ZOOM_BUTTON_ALPHA;
    _zoomButtonOut.alpha = ZOOM_BUTTON_ALPHA;
    [self showPDFandImage:_currentPlaylistItem];
  }
  [self scrollViewDidEndDecelerating:nil];
 }

It's weird that this works for iOS 6 but not iOS 7

Here are the NSLog errors when a video does not load/play: <Error>: CGImageCreate: invalid image size: 0 x 0. and: _itemFailedToPlayToEnd: { kind = 1; new = 2; old = 0; }

4

6 回答 6

4

这将是两个问题

  1. 网址有问题

    a) 如果它是从 api 获取的,你必须写,[NSUrl urlwithString:"your url string"];

    // 你的 url 字符串不是 youtube url 字符串。

    b) 如果它来自捆绑路径:[NSUrl fileWithPath:"Your path"];

  2. 源类型有问题。

    将 scouce 类型设置为任何一种,如果它不起作用,则设置为其他类型,反之亦然

    yourPlayerController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
    

    或者

    yourPlayerController.moviePlayer.movieSourceType = MPMovieSourceTypeUnknown;
    
于 2014-06-13T06:58:33.120 回答
2

我在 iOS 7 版本上遇到了同样的问题。请问您的视频网址中是否有空格和数字?

i.e. my url was something like "video title 5.2.5.mov" and when I escaped the string using the NSUTF8StringEncoding, the result was "video%20title%205.2.5.mov" and it didn't work.

I tried changing the movie url to video_title_5_2_5.mov" and it loaded fine

希望这个建议能有所帮助

于 2013-10-02T20:30:27.157 回答
1

给那些实现本地文件缓存的人的提示:包括文件扩展名

我的一个应用程序中有一个本地下载缓存,它不区分文件类型[无论好坏],导致文件没有与之关联的类型。当我将文件从服务器直接提供到电影控制器时,文件播放正常,但是当它本地存储到路径中时:[AppDocumentsDirectory]/123(没有扩展名)它无法播放。当我将文件存储为 123.mp4 时,它成功了。

于 2014-02-24T21:20:20.707 回答
0

我最终在一个实际的 ipod 上测试了该应用程序 - 它工作正常。使用 mpmoviecontroller 初始化的 url 没有我需要转义的任何空格。希望这会有所帮助......视频在模拟器上不起作用,这让我很失望

于 2014-02-26T06:50:33.113 回答
0

我遇到了同样的问题。首先检查您要播放该视频的文件是否存在。然后播放。就我而言,我的文件位于文档目录 .so

    BOOL hasVideoFile= [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@",[self getDocumentDirectory] videoFileName]];
    if (!hasVideoFile) {
        //No video found
        NSLog(@"Video file doesn't exists in this directory");
    }
于 2015-03-05T11:09:10.137 回答
0

我遇到了同样的问题,通过设置解决了

[MPMoviePlayerViewController.moviePlayer setShouldAutoplay:YES]

我看到的问题是电影播放器​​会推到导航控制器上,但是当它出现时它会消失,我会在日志中收到 _itemFailedToPlayToEnd 错误

于 2014-07-17T16:21:56.613 回答