Recent

Author Topic: AVPlayer - have sound, but no video  (Read 348 times)

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1282
  • Former Delphi 1-7, 10.2 User
AVPlayer - have sound, but no video
« on: August 08, 2020, 11:31:50 am »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.PlayButtonClick(Sender: TObject);
  2. begin
  3.   //
  4.   // 1. Create a URL
  5.   //
  6.   URL := NSURL.URLWithString(NSSTR(PAnsiChar('https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_ts/master.m3u8')));
  7.   if(Url = Nil) then
  8.     ShowMessage('NSURL.URLWithString failed!');
  9.  
  10.   //
  11.   // 2. Create AVPlayer object
  12.   //
  13.   myAsset := AVAsset.alloc.assetWithURL(URL);
  14.   myPlayerItem := AVPlayerItem.alloc.initWithAsset(myAsset);
  15.   myPlayer := AVPlayer.alloc.initWithPlayerItem(myPlayerItem);
  16.  
  17.   while(myPlayer.Status = AVPlayerStatusUnknown)
  18.     do
  19.       application.processmessages;
  20.  
  21.   if(myPlayer.Status = AVPlayerStatusFailed) then
  22.     ShowMessage('AVplayer status: failed')
  23.   else if(myPlayer.Status = AVPlayerStatusReadyToPlay) then
  24.     ShowMessage('AVplayer status: ready to play');
  25.  
  26.   //
  27.   // 3. Creete playerView object to display video
  28.   //
  29.   myPlayerView.alloc.setPlayer(myPlayer);
  30.   myPlayerView.setControlsStyle(1);  // inline
  31.  
  32.   if(myPlayerView.isReadyForDisplay) then
  33.     ShowMessage('AVPlayerView ready for display')
  34.   else
  35.     ShowMessage('AVPlayerView not ready for display');
  36.  
  37.   //
  38.   // 4. Play
  39.   //
  40.   myPlayer.play;
  41. end;  
  42.  

I thought this ws going to be simple but I was only half right - I have sound, but no video.

* AVplayer status: ready to play - yes
* AVPlayerView ready for display - no (delay before makes no difference)

Obviously there's something wrong with my AVPlayerView setup. Any ideas?
Lazarus 2.1 r64368 FPC 3.3.1 r48100 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.1 r64455 3.3.1 r48840   macOS 11.2.2 aarch64 Xcode 12.4
Lazarus 2.1 r61574 3.3.1 r42318 FreeBSD 12.1 amd64 VMware VM
Lazarus 2.1 r61574 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 3.2.0 Win10 Parallels VM

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1282
  • Former Delphi 1-7, 10.2 User
Re: AVPlayer - have sound, but no video
« Reply #1 on: August 17, 2020, 09:58:20 am »
Slightly further forward. I finally noticed that:

Code: Pascal  [Select][+][-]
  1. myPlayerView.alloc.setPlayer(myPlayer);

need to be changed to:

Code: Pascal  [Select][+][-]
  1.  
  2. myPlayerView := AVPlayerView.alloc.initWithFrame(CGRectMake(0,0,500,500));
  3. myPlayerView.setPlayer(myPlayer);

to actually create myPlayerView ... but still no video :(
Lazarus 2.1 r64368 FPC 3.3.1 r48100 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.1 r64455 3.3.1 r48840   macOS 11.2.2 aarch64 Xcode 12.4
Lazarus 2.1 r61574 3.3.1 r42318 FreeBSD 12.1 amd64 VMware VM
Lazarus 2.1 r61574 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 3.2.0 Win10 Parallels VM

 

TinyPortal © 2005-2018