首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >尝试从pushNamed中的参数中访问视频url时出错

尝试从pushNamed中的参数中访问视频url时出错
EN

Stack Overflow用户
提问于 2019-11-23 09:21:28
回答 1查看 2.4K关注 0票数 0

我正试图通过video controller通过pushNamed传递网址。

我所面对的error如下所示

代码语言:javascript
运行
复制
I/ExoPlayerImpl(29662): Release 2d82dca [ExoPlayerLib/2.9.6] [ASUS_X00T_2, ASUS_X00TD, asus, 28] [goog.exo.core]
I/flutter (29662): https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4
E/BufferQueueProducer(29662): [SurfaceTexture-0-29662-5] cancelBuffer: BufferQueue has been abandoned
I/chatty  (29662): uid=10085(com.example.demo_app) JNISurfaceTextu identical 5 lines
E/BufferQueueProducer(29662): [SurfaceTexture-0-29662-5] cancelBuffer: BufferQueue has been abandoned
D/SurfaceUtils(29662): disconnecting from surface 0x7b16f15010, reason disconnectFromSurface
I/ExoPlayerImpl(29662): Init 3c27ac9 [ExoPlayerLib/2.9.6] [ASUS_X00T_2, ASUS_X00TD, asus, 28]
I/OMXClient(29662): IOmx service obtained
D/SurfaceUtils(29662): connecting to surface 0x7b17399010, reason connectToSurface
I/MediaCodec(29662): [OMX.qcom.video.decoder.avc] setting surface generation to 30373895
D/SurfaceUtils(29662): disconnecting from surface 0x7b17399010, reason connectToSurface(reconnect)
D/SurfaceUtils(29662): connecting to surface 0x7b17399010, reason connectToSurface(reconnect)
I/ExtendedACodec(29662): setupVideoDecoder()
I/ExtendedACodec(29662): Decoder will be in frame by frame mode
D/SurfaceUtils(29662): set up nativeWindow 0x7b17399010 for 1280x720, color 0x7fa30c06, rotation 0, usage 0x20002900
W/MapperHal(29662): buffer descriptor with invalid usage bits 0x2000
W/MapperHal(29662): buffer descriptor with invalid usage bits 0x2000
I/OMXClient(29662): IOmx service obtained
I/ACodec  (29662): codec does not support config priority (err -2147483648)
I/ACodec  (29662): codec does not support config priority (err -2147483648)
I/ACodec  (29662): codec does not support config operating rate (err -2147483648)
W/ExtendedACodec(29662): Failed to get extension for extradata parameter
W/MapperHal(29662): buffer descriptor with invalid usage bits 0x2000
D/SurfaceUtils(29662): set up nativeWindow 0x7b17399010 for 1280x720, color 0x7fa30c06, rotation 0, usage 0x20002900
W/MapperHal(29662): buffer descriptor with invalid usage bits 0x2000
I/chatty  (29662): uid=10085(com.example.demo_app) CodecLooper identical 1 line
W/MapperHal(29662): buffer descriptor with invalid usage bits 0x2000
W/MapperHal(29662): buffer descriptor with invalid usage bits 0x2000
W/MapperHal(29662): buffer descriptor with invalid usage bits 0x2000
I/flutter (29662): https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4
I/flutter (29662): https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4
I/flutter (29662): https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4
I/flutter (29662): https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4
I/flutter (29662): https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4
I/flutter (29662): https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4
I/flutter (29662): https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4
I/flutter (29662): https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4
I/flutter (29662): https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4
Lost connection to device.

DemoShowScreen的代码如下所示

代码语言:javascript
运行
复制
import 'package:flutter/material.dart';
import '../../models/show.dart';
import 'package:video_player/video_player.dart';

class DemoShow extends StatefulWidget {

  static const id = "show_show_screen";

  @override
  _DemoShowState createState() => _DemoShowState();
}

class _DemoShowState extends State<DemoShow> {
  VideoPlayerController _controller;
  Future<void> _initializeVideoPlayerFuture;
  Show data;

  var media;

  @override
  void initState() {
    // Create and store the VideoPlayerController. The VideoPlayerController
    // offers several different constructors to play videos from assets, files,
    // or the internet.
      media = 'https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4';
      _controller = VideoPlayerController.network(media);      
      // Initialize the controller and store the Future for later use.
      _initializeVideoPlayerFuture = _controller.initialize();

      // Use the controller to loop the video.
      _controller.setLooping(false);


    super.initState();
  }

  @override
  void dispose() {
    // Ensure disposing of the VideoPlayerController to free up resources.
    _controller.dispose();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    data = ModalRoute.of(context).settings.arguments;
    setState(() {
      media = data.mediaUrl;
      print(media);
    });
    return Scaffold(
      appBar: AppBar(
        title: Text('${data.title}', style: Theme.of(context).textTheme.title,),
      ),
      // Use a FutureBuilder to display a loading spinner while waiting for the
      // VideoPlayerController to finish initializing.
      body: SingleChildScrollView(
        child: Container(
          child: Column(
            children: <Widget>[
              FutureBuilder(
                future: _initializeVideoPlayerFuture,
                builder: (context, snapshot) {
                  if (snapshot.connectionState == ConnectionState.done) {
                    // If the VideoPlayerController has finished initialization, use
                    // the data it provides to limit the aspect ratio of the video.
                    return AspectRatio(
                      aspectRatio: _controller.value.aspectRatio,
                      // Use the VideoPlayer widget to display the video.
                      child: VideoPlayer(_controller),
                    );
                  } else {
                    // If the VideoPlayerController is still initializing, show a
                    // loading spinner.
                    return Center(child: CircularProgressIndicator());
                  }
                },
              ),
            ],
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          // Wrap the play or pause in a call to `setState`. This ensures the
          // correct icon is shown.
          setState(() {
            // If the video is playing, pause it.
            if (_controller.value.isPlaying) {
              _controller.pause();
            } else {
              // If the video is paused, play it.
              _controller.play();
              _controller.seekTo(Duration(seconds: 32));
            }
          });
        },
        // Display the correct icon depending on the state of the player.
        child: Icon(
          _controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
        ),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

我试图将butterfly.mp4 URL替换为bee.mp4 URL,这是从pushNamed参数获得的。

在屏幕上,我可以在视频播放器中看到butterfly.mp4帧,但它从未播放或更新过bee.mp4

另外,我试图在ModalRoute.of(context).settings.arguments;中调用initState,但最终得到了null,因此代码被删除了。

更新代码后进行编辑

视频帧改为现在的视频,但我仍然面临着播放视频的问题。

带有Stateless Widget的新代码

代码语言:javascript
运行
复制
import 'package:flutter/material.dart';
import '../../models/demo.dart';
import 'package:video_player/video_player.dart';

class DemoShowScreen extends StatelessWidget {
  static const id = "demo_show_screen";
  VideoPlayerController _controller;
  Future<void> _initializeVideoPlayerFuture;

  @override
  Widget build(BuildContext context) {
    Show data = ModalRoute.of(context).settings.arguments;
    _controller = VideoPlayerController.network(data.mediaUrl);
    _controller.setLooping(false);  
    return Scaffold(
      body: Column(
        children: <Widget>[
          Container(
            child: FutureBuilder(
              future: _controller.initialize(),
              builder: (context, snapshot) {
                if (snapshot.connectionState == ConnectionState.done) {
                  // If the VideoPlayerController has finished initialization, use
                  // the data it provides to limit the aspect ratio of the video.
                  return AspectRatio(
                    aspectRatio: _controller.value.aspectRatio,
                    // Use the VideoPlayer widget to display the video.
                    child: VideoPlayer(_controller),
                  );
                } else {
                  // If the VideoPlayerController is still initializing, show a
                  // loading spinner.
                  return Center(child: CircularProgressIndicator());
                }
              },
            ),
          ),
        ],
      ),
      floatingActionButton: FloatingActionButton(
          onPressed: () {
            // Wrap the play or pause in a call to `setState`. This ensures the
            // correct icon is shown.

              // If the video is playing, pause it.
              if (_controller.value.isPlaying) {
                _controller.pause();
              } else {
                // If the video is paused, play it.
                _controller.play();
                _controller.seekTo(Duration(seconds: 32));
              }
          },
          // Display the correct icon depending on the state of the player.
          child: Icon(
            _controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
          ),
      ),
    );
  }
}

错误代码:

代码语言:javascript
运行
复制
I/ExoPlayerImpl(22057): Release 877cbe7 [ExoPlayerLib/2.9.6] [ASUS_X00T_2, ASUS_X00TD, asus, 28] [goog.exo.core]
E/BufferQueueProducer(22057): [SurfaceTexture-0-22057-1] cancelBuffer: BufferQueue has been abandoned
I/chatty  (22057): uid=10085(com.example.demo_app) JNISurfaceTextu identical 5 lines
E/BufferQueueProducer(22057): [SurfaceTexture-0-22057-1] cancelBuffer: BufferQueue has been abandoned
D/SurfaceUtils(22057): disconnecting from surface 0x7b17aa2010, reason disconnectFromSurface
I/ExoPlayerImpl(22057): Init cf82360 [ExoPlayerLib/2.9.6] [ASUS_X00T_2, ASUS_X00TD, asus, 28]
I/OMXClient(22057): IOmx service obtained
D/SurfaceUtils(22057): connecting to surface 0x7b337e0010, reason connectToSurface
I/MediaCodec(22057): [OMX.qcom.video.decoder.avc] setting surface generation to 22586371
D/SurfaceUtils(22057): disconnecting from surface 0x7b337e0010, reason connectToSurface(reconnect)
D/SurfaceUtils(22057): connecting to surface 0x7b337e0010, reason connectToSurface(reconnect)
I/ExtendedACodec(22057): setupVideoDecoder()
I/ExtendedACodec(22057): Decoder will be in frame by frame mode
D/SurfaceUtils(22057): set up nativeWindow 0x7b337e0010 for 1280x720, color 0x7fa30c06, rotation 0, usage 0x20002900
W/MapperHal(22057): buffer descriptor with invalid usage bits 0x2000
W/MapperHal(22057): buffer descriptor with invalid usage bits 0x2000
I/OMXClient(22057): IOmx service obtained
I/ACodec  (22057): codec does not support config priority (err -2147483648)
I/ACodec  (22057): codec does not support config priority (err -2147483648)
I/ACodec  (22057): codec does not support config operating rate (err -2147483648)
W/ExtendedACodec(22057): Failed to get extension for extradata parameter
W/MapperHal(22057): buffer descriptor with invalid usage bits 0x2000
W/MapperHal(22057): buffer descriptor with invalid usage bits 0x2000
D/SurfaceUtils(22057): set up nativeWindow 0x7b337e0010 for 1280x720, color 0x7fa30c06, rotation 0, usage 0x20002900
W/MapperHal(22057): buffer descriptor with invalid usage bits 0x2000
W/MapperHal(22057): buffer descriptor with invalid usage bits 0x2000
W/MapperHal(22057): buffer descriptor with invalid usage bits 0x2000
W/MapperHal(22057): buffer descriptor with invalid usage bits 0x2000 
EN

回答 1

Stack Overflow用户

发布于 2019-11-23 09:37:08

尝试在StatelessWidget中包装完整的类,因为在构建方法之前调用了initState,

还避免在构建函数中调用setState。

代码语言:javascript
运行
复制
class WebViewPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    ArgumentData data = ModalRoute.of(context).settings.arguments;
    return Scaffold(
body:DemoShow(data.url),
    );
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59006193

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档