Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[video_player] Validate size only when assets contain video tracks on iOS #4639

Merged
merged 3 commits into from
Jan 19, 2022
Merged

[video_player] Validate size only when assets contain video tracks on iOS #4639

merged 3 commits into from
Jan 19, 2022

Conversation

AlexV525
Copy link
Member

@AlexV525 AlexV525 commented Jan 4, 2022

By adding a more specific type check, we can expand the support range of the video_player on iOS from videos to all supported media types. This is from the documentation of AVSimplePlayer: AVSimplePlayer/AVSPDocument.m#139

Resolves flutter/flutter#38480, flutter/flutter#90429, or more issues related to iOS audio playing.
Related to flutter/flutter#47105, flutter/flutter#75636.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@AlexV525
Copy link
Member Author

AlexV525 commented Jan 4, 2022

Seems the duration for audios on iOS will always be 0:00:00.001000. Drafting for further investigations.

@AlexV525 AlexV525 closed this Jan 4, 2022
@AlexV525 AlexV525 reopened this Jan 4, 2022
@AlexV525

This comment has been minimized.

// Due to the duration calculation accurancy between platforms,
// the milliseconds on Web will be a slightly different from natives.
// The audio was made with 44100 Hz, 192 Kbps CBR, and 32 bits.
if (kIsWeb) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's 5.041625 sec. The web takes 5.042 and natives take 5.041.

Copy link
Member Author

@AlexV525 AlexV525 Jan 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done some debuggin steps, and the root cause of this difference is from here:

milliseconds: (videoElement.duration * 1000).round(),

The videoElement.duration reports 5.041633 from the engine, and it seems to be the precision issue of the web platform. If we want to make them equal, we might use toInt() here.

@AlexV525 AlexV525 marked this pull request as ready for review January 5, 2022 07:40
@godofredoc godofredoc changed the base branch from master to main January 6, 2022 22:42
@stuartmorgan-g
Copy link
Contributor

I don't think this actually resolves flutter/flutter#47105 as claimed in the PR description; using video_player to play audio isn't actually a good idea, and will be even less so when if (most likely when) we migrate it to platform views.

I'm conflicted about this PR. The change itself is simple, but adding tests asserting that audio works sets a problematic precedent. What if a new platform we want to support has different APIs for supporting video and audio; are we now saying we require audio support in that implementation too? When there are inevitably new issues or feature requests that are specific to audio, will those all suddenly be valid?

I think where I come down on this is that because the mismatch with Android is currently a source of confusion, and the incremental cost is extremely low here, I'm inclined to take this PR, but:

@jmagman Does that sound good to you?

@jmagman
Copy link
Member

jmagman commented Jan 14, 2022

@jmagman Does that sound good to you?

SGTM

@AlexV525
Copy link
Member Author

AlexV525 commented Jan 15, 2022

using video_player to play audio isn't actually a good idea

That's more like it used to be supported implicitly, but someday it becomes invalid. I'll update the above suggestions.

If we're targeting flutter/flutter#47015, it actually resolves 2/3, with basic audio playing. I agree with the support range part, then the PR is more like an enhancement (validate size only with video) plus a fix (with more reliable duration obtain).

Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM with comment nit.

@AlexV525 AlexV525 added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Jan 19, 2022
@fluttergithubbot fluttergithubbot merged commit 688f052 into flutter:main Jan 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 19, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 19, 2022
@AlexV525 AlexV525 mentioned this pull request Jan 20, 2022
11 tasks
@stuartmorgan-g stuartmorgan-g mentioned this pull request Jan 20, 2022
11 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p: video_player platform-ios waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[video_player ] Ability to play local mp3 audio files.
4 participants