Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[video_player_tizen] "Invalid State" PlatformException when playing "some" live streams #732

Open
T-h-e-Wizard opened this issue Sep 4, 2024 · 6 comments

Comments

@T-h-e-Wizard
Copy link

I was able to play the sample mp4 file w/o any problems in the player, but when I changed the URL to a "live stream" one (with .ts extension), I got the following call stack in my debug log:

[E] [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(player_set_play_position failed, Invalid state, null, null)
#0      TizenVideoPlayerApi.seekTo (package:video_player_tizen/src/messages.g.dart:459:7)
<asynchronous suspension>
#1      VideoPlayerController.seekTo (package:video_player/video_player.dart:564:5)
<asynchronous suspension>
#2      VideoPlayerController.play (package:video_player/video_player.dart:458:7)
<asynchronous suspension>

This is what the VideoPlayerValue looks like for the stream, before, and after initialization:

[I] flutter: initState: VideoPlayerValue(duration: 0:00:00.000000, size: Size(0.0, 0.0), position: 0:00:00.000000, caption: Caption(number: 0, start: 0:00:00.000000, end: 0:00:00.000000, text: ), captionOffset: 0:00:00.000000, buffered: [], isInitialized: false, isPlaying: false, isLooping: false, isBuffering: false, volume: 1.0, playbackSpeed: 1.0, errorDescription: null)
[I] flutter: wrapperListener
[I] flutter: contollerListener: VideoPlayerValue(duration: 0:00:00.000000, size: Size(1280.0, 720.0), position: 0:00:00.000000, caption: Caption(number: 0, start: 0:00:00.000000, end: 0:00:00.000000, text: ), captionOffset: 0:00:00.000000, buffered: [], isInitialized: true, isPlaying: false, isLooping: false, isBuffering: false, volume: 1.0, playbackSpeed: 1.0, errorDescription: null)

Checking the call stack, it seems like, when duration is set as zero for the media metadata, flutter video_player ends up calling seekTo(Duration.zero); and this later causes an Invalid State problem(??) on Tizen player side. Can you please confirm? Are live streams not supported in this player? Would you suggest videohole, or avplay alternatives? Thanks!

@JSUYA
Copy link
Member

JSUYA commented Sep 5, 2024

Hi Thank you for your interesting :)

I was able to play the sample mp4 file w/o any problems in the player, but when I changed the URL to a "live stream" one (with .ts extension),

Can you tell me your "live stream" sample URL? Is it a valid URL or is there a network issue accessing the url from your device? Because I tested it using this sample and it works fine.

--- a/packages/video_player/example/lib/main.dart
+++ b/packages/video_player/example/lib/main.dart
@@ -219,7 +219,9 @@ class _BumbleBeeRemoteVideoState extends State<_BumbleBeeRemoteVideo> {
   void initState() {
     super.initState();
     _controller = VideoPlayerController.network(
-      'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4',
+      'https://testfileorg.netwet.net/Sample%20Video/sample_1920x1080.ts',
       closedCaptionFile: _loadCaptions(),
       videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true),
     );

The exception message that occurs when performing a SeekTo on content that is not loaded properly seems to need to be more review.

Are live streams not supported in this player?

video_player_tizen is implemented using MediaPlayer API provided by Tizen.
These APIs follow the video spec of each TV device. Therefore, please check the spec document.

videohole and avplay are for DRM streams. If you use DRM Streams, you can use the package with partner-level certificate.
And please note that videohole and avplay do not follow video_player_platform_interface.

@T-h-e-Wizard
Copy link
Author

T-h-e-Wizard commented Sep 8, 2024

@JSUYA Thank you very much for your quick, and detailed answer! 🙏
(Edit: Also, another big thanks for your work on upgrading the tizen implementation with the latest version of the video_player plugin)

Let me go through your answer paragraph by paragraph, and share my answers/thoughts:

Can you tell me your "live stream" sample URL? Is it a valid URL or is there a network issue accessing the url from your device? Because I tested it using this sample and it works fine.

The URL for the live stream I was trying contained credentials that I could not share, that was why I haven't mentioned that in my earlier post. The URL you've shared is also not quite a "live" (continuous) stream (w/o a fixed duration), but a fixed length (~28 seconds) video that the player could retrieve the duration metadata for). But thanks still for your suggestion, as I could see that the player does indeed work for another live stream that I've picked from the iptv-org / iptv repo here in github.

The exception message that occurs when performing a SeekTo on content that is not loaded properly seems to need to be more review.

The duration for that particular iptv stream was also read as zero, but it was working fine, which does invalidate my theory about seekTo(Duration.zero) possibly being the root cause the exception. So yes, the stream's particulars are more relevant as you've said.

Are there any particular debugging suggestions there? As far as I can see, dlog is disabled on tizen devices (or at least on the TV I'm working with), right? It's going to be a bit cumbersome setting up packet capture, and that may not be sufficient.

These APIs follow the video spec of each TV device. Therefore, please check the spec document.

The TV is a '24 model Q series one. So it shouldn't be skimping on codec/etc support I'm guessing, but I'll compare the working/non-working live streams in detail to make sure, and increase my own debugging coverage.

@T-h-e-Wizard T-h-e-Wizard changed the title [video_player_tizen] "Invalid State" PlatformException when playing live stream (i.e. duration==0) [video_player_tizen] "Invalid State" PlatformException when playing "some" live streams Sep 8, 2024
@JSUYA
Copy link
Member

JSUYA commented Sep 10, 2024

Checking the call stack, it seems like, when duration is set as zero for the media metadata, flutter video_player ends up calling seekTo(Duration.zero); and this later causes an Invalid State problem(??) on Tizen player side.

While checking the streaming functionality of video_player, I found that the player is having issues with the duration being set to 0 during the initialization step in this content case. It seems that we need a feature that updates the duration in real time during video streaming.
(Currently, we check the duration of the video during the initial step.)

This PR temporarily sets the duration to a non-zero value. So seekTo() operation using progress will not work properly. We will improve this in the future.

I hope this helps you.

Are there any particular debugging suggestions there? As far as I can see, dlog is disabled on tizen devices (or at least on the TV I'm working with), right? It's going to be a bit cumbersome setting up packet capture, and that may not be sufficient.

dlog is not support on TV due to VD's security policy. There is currently no way to check the dlog.

@T-h-e-Wizard
Copy link
Author

Thanks again for the quick return (even w/ a code-fix/workaround)!

That change indeed meant progress for the particular stream I was working with! The player at least started playing audio of the stream. The video wasn't shown, and the audio unfortunately stopped after 20-30 seconds, but those can probably be narrowed down to the stream codec/etc. What VLC shows for that stream is below [1] btw. It's one unlucky stream I'm afraid - I'll keep on testing w/ a broader list of streams, to see if that's an exception, or a typical stream from this provider.

Also, I wanted to let you know that a Duration of 0 probably was not the "only" reason this stream was messing up the player. As I've mentioned earlier, the 2.5.0 player was able to play other test streams (http - https) (from iptv.org repo)(where a non-zero intial size was read) even though the duration was also 0 (my log details below) [2]. As you can see in the logs, there was another exception, ("not implemented" for player_set_playback_rate) and a delay before the playback started, but it was being played anyway!

(Yet another note: With your current workaround, there may be a risk (as I could see from the my logs), that the video_player # isCompleted API property is set to true prematurely (?) for the live streams you've added the special case for - this may confuse some users/implementations - also probably because of this, there were much fewer notifications sent to listeners by VideoPlayerController for live streams)

[1]

Stream 0 
   Original ID: 256 
   Codec. H264 - MPEG-4 AVC (part 10) (h264) 
   Type: Video 
   Video resolution: 1280x720 
   Buffer dimensions: 1280x720 
   Frame rate: 25 
   Decoded format: 
   Orientation: Top left 
   Color primaries: ITU-R BT.709 
   Color transfer function: ITU-R BT.709 
   Color space: ITU-R BT.709 Range 
   Chroma location: Left 
Stream 1 
   Original ID: 257 
   Codec: ADTS 
   Type: Audio 
   Channels: Stereo 
   Sample rate: 48000 Hz 
   Bits per sample: 32 

[2]

[I] flutter: New Media selected: http-FashionTV
[I] flutter: initState: isInitialized: false - isPlaying: false - isCompleted: false - position: 0:00:00.000000 - duration: 0:00:00.000000 - size: Size(0.0, 0.0)      
[I] flutter: listener : isInitialized: true  - isPlaying: false - isCompleted: false - position: 0:00:00.000000 - duration: 0:00:00.000000 - size: Size(800.0, 450.0)

[I] flutter: listener : isInitialized: true  - isPlaying: true  - isCompleted: false - position: 0:00:00.000000 - duration: 0:00:00.000000 - size: Size(800.0, 450.0)

[E] [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(player_set_playback_rate failed, Function not implemented, null, null) 
#0      TizenVideoPlayerApi.setPlaybackSpeed (package:video_player_tizen/src/messages.g.dart:388:7)
<asynchronous suspension>
#1      VideoPlayerController._applyPlaybackSpeed (package:video_player/video_player.dart:623:5)
<asynchronous suspension>
#2      VideoPlayerController._applyPlayPause (package:video_player/video_player.dart:597:7)
<asynchronous suspension>
#3      VideoPlayerController.play (package:video_player/video_player.dart:548:5)
<asynchronous suspension>
[I] flutter: listener : isInitialized: true  - isPlaying: true  - isCompleted: true  - position: 0:00:00.000000 - duration: 0:00:00.000000 - size: Size(800.0, 450.0)
[I] flutter: listener : isInitialized: true  - isPlaying: false - isCompleted: true  - position: 0:00:00.000000 - duration: 0:00:00.000000 - size: Size(800.0, 450.0)

@T-h-e-Wizard
Copy link
Author

Guess what!?!!!... An important part of the problems about my test streams turned out to be due to some inconsistent workspace problem!... When a debug version of the program wasn't running at all on the TV (even though it had very minor/insignificant changes compared to an earlier running version), I tried a --release version and to my big surprise, even the problematic streams were working now!!?! :)

After running flutter-tizen clean, and flutter-tizen pub get, the debug version was behaving much better as well! So it seems my VSCode workspace was somehow corrupted / became inconsistent...

(I've tried going back to 2.5.0 in this new workspace, and the test streams did NOT work - so set the duration=1 workaround definitely makes things better for them. I'll leave it up to you to close the issue or not (keep it open to commit a full fix, or close it w/ the workaround)).
(BTW, the full flutter directory (with bin/dart.bat) being under flutter-tizen directory (w/o a bin/dart.bat) is the expected structure, right? - That seemed a little strange to me at first (or I've probably messed up the installation steps!?))

@JSUYA
Copy link
Member

JSUYA commented Sep 13, 2024

so set the duration=1 workaround definitely makes things better for them.

In VideoPlayer's play(), if position and duration are the same, call seekTo(Duration.zero); (as you mentioned above).
https://github.com/flutter/packages/blob/main/packages/video_player/video_player/lib/video_player.dart#L543

So I added a patch to get the duration of live streaming content from TV. (Of course, there are still issues with non-TV profiles.)
#742

I'll leave it up to you to close the issue or not

I will close this once #742 is merged.

(BTW, the full flutter directory (with bin/dart.bat) being under flutter-tizen directory (w/o a bin/dart.bat) is the expected structure, right? - That seemed a little strange to me at first (or I've probably messed up the installation steps!?))

flutter-tizen writes the version of flutter supported by flutter-tizen (and flutter-tizen/embedder) here and syncs the commit when executing the flutter-tizen command.
dart is in flutter-tizen/flutter/bin.

$ pwd
/home/junsu/dev/os/f-project/flutter-tizen/flutter/bin
$ ls -al
total 32
drwxrwxr-x  4 junsu junsu 4096 Sep  5 17:08 .
drwxrwxr-x 10 junsu junsu 4096 Sep  5 17:09 ..
drwxrwxr-x  7 junsu junsu 4096 Sep  5 17:17 cache
-rwxrwxr-x  1 junsu junsu 2145 Dec  5  2023 dart
-rw-rw-r--  1 junsu junsu 1488 Feb  9  2023 dart.bat
-rwxrwxr-x  1 junsu junsu 2372 Aug 28 18:59 flutter
-rw-rw-r--  1 junsu junsu 2544 Aug 28 18:59 flutter.bat
drwxrwxr-x  2 junsu junsu 4096 Sep  3 11:18 internal

If you need help, could you please create a new issue with more details?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants