fluttercommunity / chewie

The video player for Flutter with a heart of gold
MIT License
1.94k stars 1.01k forks source link

run in web but can not play the network video #522

Open stars-one opened 3 years ago

stars-one commented 3 years ago

I find that network video cannot be played by this,is there a way to resolve this problem?Thanks so much

Following is the error in the console of chrome

errors.dart:187 Uncaught (in promise) Error: PlatformException(channel-error, Unable to establish connection on channel., null, null)
    at Object.throw_ [as throw] (errors.dart:236)
    at seekTo (messages.dart:357)
    at seekTo.next (<anonymous>)
    at async_patch.dart:45
    at _RootZone.runUnary (zone.dart:1613)
    at _FutureListener.thenAwait.handleValue (future_impl.dart:155)
    at handleValueCallback (future_impl.dart:707)
    at Function._propagateToListeners (future_impl.dart:736)
    at _Future.new.[_completeWithValue] (future_impl.dart:542)
    at async._AsyncCallbackEntry.new.callback (future_impl.dart:580)
    at Object._microtaskLoop (schedule_microtask.dart:40)
    at _startMicrotaskLoop (schedule_microtask.dart:49)
    at async_patch.dart:166

My page code

import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';

import 'MyMaterialPage.dart';

class VideoPage extends StatefulWidget {
  //https://nico-android-apk.oss-cn-beijing.aliyuncs.com/landscape.mp4
  final String playUrl = "https://v-cdn.zjol.com.cn/280443.mp4";

  // VideoPage(this.playUrl);
  @override
  _VideoPageState createState() => _VideoPageState();
}

class _VideoPageState extends State<VideoPage> {
  VideoPlayerController _videoPlayerController;
  ChewieController _chewieController;

  @override
  void initState() {
    super.initState();
    _videoPlayerController = VideoPlayerController.network(widget.playUrl);
    _chewieController = ChewieController(
      videoPlayerController: _videoPlayerController,
      autoPlay: false,
      //aspectRatio: 3 / 2.0,
      //customControls: CustomControls(),
    );
  }

  @override
  void dispose() {
    _videoPlayerController.dispose();
    _chewieController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MyMaterialPage(
        "视频播放demo",
        Container(
          child: Chewie(controller: _chewieController,),
        ));

  }
}

class MyMaterialPage extends StatelessWidget{
  String title;
  Widget content;

  MyMaterialPage(this.title, this.content);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(title),
      ),
      body: content
      // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

}
Zahra-H commented 3 years ago

I have the same problem. My code is OK on iOS and android. I have problem on web, when i open my app from iPhone browsers like Safari, Chrome, Firefox, it's has just sound(white picture). Any solution?

joelbrostrom commented 3 years ago

You don't run

await _videoPlayerController.initialize();

Could that be it?