video_player包在iOS上无法播放mp4文件,但在Android上可以。

huangapple go评论72阅读模式
英文:

video_player package not able to play mp4-files on iOS but android

问题

I am downloading mp4 file from Firestore.
Then I sure it in the Cache with the ChaceManager. Like:

 dev.log(name: 'Resource_Explorer', 'Trying to chace Video: $videoName');
 final storageRef = _firebaseStorage.ref(path);
 final fileData = await storageRef.getData();
 return ExplorerFileInfo(await cacheinstance.putFile(path, fileData!, key: path), FileState.downloaded);

Then I provide the Video to my Video Player as:

final videoFile = (await resourceExplorer.getVideoFile(videoPath)).value;

Everything works fine on Android. But on iOS I'm getting the error:

[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(VideoError, Failed to load video: Cannot Open, null, null)

I searched for the error 'Failed to load video: Cannot Open' and found a GitHub issue which is still open. But only one person had the same 'Cannot Open' as me. They are getting an error like: 'Failed to load video: Operation Stopped'. And this issue is still unsolved. And seems to be an HTTP error.

I am able to play the same video from my assets. And I am able to do the same steps to display an image on iOS and on Android.

I would be grateful for any help. Thanks in advance!


Update:

After I downloaded the file with the Duo package instead of .getData(), I was able to deliver the file as a desired mp4 and play it with the video_player.

But if I save the data in the cache with the cache manager, I will get the data as .file and video_player is not able to play .file files on iOS.

英文:

I am downloading mp4 file from Firestore.
Then I sure it in the Cache with the ChaceManager. Like:

 dev.log(name: 'Resource_Explorer', 'Trying to chace Video: $videoName');
      final storageRef = _firebaseStorage.ref(path);
      final fileData = await storageRef.getData();
      return ExplorerFileInfo(await cacheinstance.putFile(path, fileData!, key: path), FileState.downloaded);

Then I provide the Video to my Video Player as:

final videoFile = (await resourceExplorer.getVideoFile(videoPath)).value;

Everything works fine on Android. But on IOS im getting the error:<br>
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(VideoError, Failed to load video: Cannot Open, null, null) <br>

I searched for the error 'Failed to load video: Cannot Open' and found GitHub issue which is still open. but only one person had the same 'Cannot Open' as me. They are getting error like: 'Failed to load video: Operation Stopped,'. And this issue is still unsolved. And seems to be a Http error.

I am able to play the same video from my assets. And I am able to do the same steps to display an Image on IOS and on Android.

I would be greatful for any help. Thanks in advance!


Update:<br>
After I downloaded the file with the Duo package instead of .getData(), I was able to deliver the file as wished mp4 and play it with the video_player. <br>
But if I safe the data in the cache with the cache manager, I will get the data as .file and video_player is not able to play .file files on iOS.

答案1

得分: 0

I solved the Problem.

Somehow is video_player able to open "*.file" on Android, but on iOS!

To solve the problem you have to rename your videoFile like:

final videoFile = (await resourceExplorer.getVideoFile(videoPath)).value;
String videoFilePath = videoFile.path;
String videoFilePathAsMp = '${videoFilePath.substring(0, videoFilePath.length - 4)}mp4';
final renamedVideo = await videoFile.rename(videoFilePathAsMp);
_vpController = VideoPlayerController.file(renamedVideo)
  ..addListener(() => setState(() {}))
  ..setLooping(true)
  ..setVolume(0.0)
  ..initialize().then((_) => _vpController!.play());
英文:

I solved the Problem.

Somehow is video_player able to open "*.file" on Android, but on iOS!

To solve the problem you have to rename your videoFile like:

      final videoFile = (await resourceExplorer.getVideoFile(videoPath)).value;
      String videoFilePath = videoFile.path;
      String videoFilePathAsMp = &#39;${videoFilePath.substring(0, videoFilePath.length - 4)}mp4&#39;;
      final renamedVideo = await videoFile.rename(videoFilePathAsMp);
      _vpController = VideoPlayerController.file(renamedVideo)
        ..addListener(() =&gt; setState(() {}))
        ..setLooping(true)
        ..setVolume(0.0)
        ..initialize().then((_) =&gt; _vpController!.play());

huangapple
  • 本文由 发表于 2023年5月7日 22:44:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76194607.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定