Recent

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

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 929
  • 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?
o Lazarus v2.1.0 r63871, FPC v3.3.1 r46876, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware Fusion VM)
o FPC 3.0.4, FreeBSD 12.2-STABLE r365646 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 929
  • 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 :(
o Lazarus v2.1.0 r63871, FPC v3.3.1 r46876, macOS 10.14.6 (with sup update), Xcode 11.3.1
o Lazarus v2.1.0 r61574, FPC v3.3.1 r42318, FreeBSD 12.1 amd64 (VMware Fusion VM)
o FPC 3.0.4, FreeBSD 12.2-STABLE r365646 amd64
o Lazarus v2.1.0 r61574, FPC v3.0.4, Ubuntu 18.04 (Parallels VM)

 

TinyPortal © 2005-2018