admin管理员组

文章数量:1123040

I am building a WebView-based app for Android TV using Flutter. While most websites work fine, the app encounters an issue when trying to load pages that include video content. Specifically, when navigating to a video, I get the following error in the logs:

Error Logs:

[AndroidInAppWebViewController] (android) WebView ID 0 calling "onReceivedError" using {request: {headers: {sec-ch-ua: "Android WebView";v="131", "Chromium";v="131", "Not_A Brand";v="24", sec-ch-ua-mobile: ?1, Accept: */*, sec-ch-ua-platform: "Android", User-Agent: Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Mobile Safari/537.36, Referer: , Accept-Encoding: identity;q=1, *;q=0, Range: bytes=0-}, isRedirect: false, method: GET, hasGesture: false, isForMainFrame: false, url: .mp4}, error: {description: net::ERR_FAILED, type: -1}}
[log] WebView request error: net::ERR_FAILED
       url : .mp4 
      type : UNKNOWN

Observations: •

Videos Fail to Load: The WebView does not render videos and throws a net::ERR_FAILED error.

• Non-Video Content Works: Regular pages load without issues.

• Works in Browser: The website, including videos, works correctly in a desktop or mobile browser. I suspect the issue might relate to WebView settings, video streaming protocols, or Android TV compatibility.

Code:

Below is the relevant part of my implementation:

import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:get/get.dart';

class WebViewWidget extends StatelessWidget {
  final HomeController homeController;

  const WebViewWidget({super.key, required this.homeController});

  @override
  Widget build(BuildContext context) {
    return InAppWebView(
      initialSettings: _webViewSettings(),
      initialUrlRequest: URLRequest(
        url: WebUri(homeController.url.value),
      ),
      onWebViewCreated: (controller) {
        homeController.webViewController = controller;
        homeController.setLoading(true);
      },
      onLoadStart: (controller, url) async {
        homeController.setLoading(true);
        log('WebView started loading: $url');
      },
      onLoadStop: (controller, url) {
        homeController.setLoading(false);
        log('WebView finished loading: $url');
      },
      onLoadError: (controller, url, code, description) {
        homeController.setLoading(false);
        log('WebView error [$code]: $description at $url');
      },
    );
  }

  InAppWebViewSettings _webViewSettings() {
    return InAppWebViewSettings(
      javaScriptEnabled: true,
      mediaPlaybackRequiresUserGesture: false,
      mixedContentMode: MixedContentMode.MIXED_CONTENT_ALWAYS_ALLOW,
      userAgent:
          "Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Mobile Safari/537.36",
    );
  }
}

本文标签: flutterAndroid TV WebView App Fails to Load Videos netERRFAILEDStack Overflow