Flutter iOS 中视频无法播放并出现错误

问题描述 投票:0回答:8

Flutter iOS 中视频无法播放并出现错误 未处理的异常:PlatformException(VideoError,无法加载视频:操作已停止,null,null)。在安卓上运行良好。如果您对此有任何想法,请告诉我。

=>使用video_player插件

=>代码链接= https://drive.google.com/file/d/1amGVhtz0CrnG5ocbjWImW79-XYRlXguN/view?usp=sharing

视频=http://143.244.137.15:8000/media/event/org_event_video/None/event_video_4pnqGxk.mp4

=>信息.plist

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
    <key>CFBundleDisplayName</key>
    <string>Evento Package</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>evento_package</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>$(FLUTTER_BUILD_NAME)</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>$(FLUTTER_BUILD_NUMBER)</string>
    <key>FirebaseAppDelegateProxyEnabled</key>
    <string>0</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>UIBackgroundModes</key>
    <array>
        <string>fetch</string>
        <string>remote-notification</string>
    </array>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIMainStoryboardFile</key>
    <string>Main</string>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSAllowsArbitraryLoadsForMedia</key>
        <true/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>143.244.137.15:8000</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
        </dict>
    </dict>
</dict>
</plist>
ios flutter video flutter-ios
8个回答
3
投票

在iOS上,我找到了解决这个问题的方法。 URL 需要是 HTTPS,并且应用程序需要在设备上而不是模拟器上运行。



0
投票

问题可以有多种解决方案:

  1. HTTP 问题 - 此问题可以通过设置 NSAppTransportSecurity - NSAllowsArbitraryLoads - true 来解决。然而,就我而言,这不是问题。

  2. 模拟器问题 - 这个问题可以通过使用物理设备而不是模拟器来解决。然而,就我而言,这也不是问题。

  3. 服务器端数据传输问题:

通过这些链接,您会发现关键是将 Content-Range 添加到标题中。就我而言,我使用第三种解决方案更改了服务器发送视频的方式,并且它工作正常。

希望这个答案能够帮助到很多 Flutter 开发者。


0
投票

就我而言,当我不再使用现已弃用的 VideoPlayerController.network 构造函数时,问题就出现了:

String path = "https://example.com/myfile.mp4?alt=media&token=ab1-cd2";
var videoPlayerController = VideoPlayerController.network(path);

并切换到:

String path = "https://example.com/myfile.mp4?alt=media&token=ab1-cd2";
var uri = Uri(path: path); // problematic due to percent-encoding
var videoPlayerController = VideoPlayerController.networkUrl(uri);

我的问题实际上是我新使用的默认 Uri 构造函数。

uri
包含百分比编码,VideoPlayer 无法处理。 (例如:“https%3A//example.com/myfile.mp4%3Falt=media&token=ab1-cd2”)

我通过使用不同的 Uri 构造函数来让它工作:

String path = "https://example.com/myfile.mp4?alt=media&token=ab1-cd2";
var uri = Uri.parse(path); // works correctly; has no percent-encoding
var videoPlayerController = VideoPlayerController.networkUrl(uri);

0
投票

如何解决这个错误, 错误:找不到类型“AVFoundationVideoPlayerApi”。

我在此版本的视频播放器 video_player 中工作:^2.8.5 视频将无法播放,它显示 AVFoundationVideoPlayerApi 未找到


-2
投票

我找到了解决方案,如下链接: https://github.com/flutter/flutter/issues/56665#issuecomment-1235279217

我没有将以下内容添加到 Info.plist:

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>

希望能帮到你。


-3
投票

尝试: 问题在于返回视频链接的 API,似乎在 iOS 上它需要一个标头来指定要发送的字节范围。通过添加此标头,视频将按预期工作。

降级您的插件或 flutter/升级您的插件或 flutter

编辑:将其添加到您的 ios/Runner/info.plist

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>

编辑:允许不安全的连接

  1. 转到你的xcode
  2. 转到 ios/runner/info.plist
  3. 右侧面板上将有键、类型和值选项卡
  4. 转到信息属性列表/应用程序传输安全设置/例外域/您的域
  5. NSException允许不安全HTTP负载
  6. 允许“是”

-3
投票

我也有同样的问题。解决方案非常简单。我的视频无法在我的手机上播放。它的编码不正确。当我正确编码时,问题就解决了。

© www.soinside.com 2019 - 2024. All rights reserved.