【问题标题】:Flutter VideoPlayer didn't play youtube videoFlutter VideoPlayer 无法播放 youtube 视频
【发布时间】:2021-05-29 18:45:30
【问题描述】:

我正在开发颤振应用程序并使用 ext_video_player 播放 youtube 视频。当我在视频播放器上播放我的频道视频时,它不起作用。但是我添加了来自 youtube 的任何视频,播放器正在工作。为什么会这样?

import 'package:ext_video_player/ext_video_player.dart';

controller = VideoPlayerController.network(
    //example video
    'https://www.youtube.com/watch?v=TdrL3QxjyVw'  
    //my video
    //'https://www.youtube.com/watch?v=GoqggeA-ctA'
      )
    ..initialize().then((value) {
      controller.setLooping(true);
      controller.play();
      widget.sets.controller = controller;
      widget.onInitialized();
    });

Widget build(BuildContext context) => SizedBox(
    child: controller.value.initialized
        ? VideoPlayer(controller)
        : Center(child: CircularProgressIndicator()),
  );
  • 工作视频“https://www.youtube.com/watch?v=TdrL3QxjyVw”
  • 我的视频(无效)“https://www.youtube.com/watch?v=GoqggeA-ctA”

错误:

I/ExoPlayerImpl( 4553): Init 16226c0 [ExoPlayerLib/2.13.2] [generic_x86_arm, sdk_gphone_x86, Google, 30]
E/ExoPlayerImplInternal( 4553): Playback error
E/ExoPlayerImplInternal( 4553):   com.google.android.exoplayer2.ExoPlaybackException: Source error
E/ExoPlayerImplInternal( 4553):       at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:579)
E/ExoPlayerImplInternal( 4553):       at android.os.Handler.dispatchMessage(Handler.java:102)
E/ExoPlayerImplInternal( 4553):       at android.os.Looper.loop(Looper.java:223)
E/ExoPlayerImplInternal( 4553):       at android.os.HandlerThread.run(HandlerThread.java:67)
E/ExoPlayerImplInternal( 4553):   Caused by: com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (FlvExtractor, FlacExtractor, WavExtractor, FragmentedMp4Extractor, Mp4Extractor, AmrExtractor, PsExtractor, OggExtractor, TsExtractor, MatroskaExtractor, AdtsExtractor, Ac3Extractor, Ac4Extractor, Mp3Extractor, JpegExtractor) could read the stream.
E/ExoPlayerImplInternal( 4553):       at com.google.android.exoplayer2.source.BundledExtractorsAdapter.init(BundledExtractorsAdapter.java:92)
E/ExoPlayerImplInternal( 4553):       at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1026)
E/ExoPlayerImplInternal( 4553):       at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:415)
E/ExoPlayerImplInternal( 4553):       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/ExoPlayerImplInternal( 4553):       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/ExoPlayerImplInternal( 4553):       at java.lang.Thread.run(Thread.java:923)
E/flutter ( 4553): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(VideoError, Video player had error com.google.android.exoplayer2.ExoPlaybackException: Source error, null, null)

谢谢,祝你有美好的一天。

【问题讨论】:

  • 您是否考虑过使用youtube_player_flutter 代替pub.dev/packages/youtube_player_flutter 播放youtube 视频
  • 感谢您的建议。是的,我考虑过。但我必须在我的代码中使用 VideoPlayerController,所以我不使用它..
  • 视频播放必须有特定格式的视频才能播放。此链接可能无效。解决方法是解析此 url 以获取 .mp4 或其他能够播放的实际视频文件链接。

标签: flutter youtube video-player flutter-video-player


【解决方案1】:

问题是由 youtube 的上传格式引起的。 当我使用 h.264 + aac 编解码器将 mp4 文件转换为 mp4 并上传 youtube 时,播放器播放我的视频。它的上传格式问题。

【讨论】:

  • 你能解释更多吗,因为我面临与“video_player”相同的问题。
【解决方案2】:

使用 youtube_player_flutter 包 与版本: youtube_player_flutter:^ 6.1.1

这是我从 youtube 频道检索视频的代码示例

class Video {
  final String id;
  final String title;
  final String thumbnailUrl;
  final String channelTitle;

  Video({
    this.id,
    this.title,
    this.thumbnailUrl,
    this.channelTitle,
  });

  factory Video.fromMap(Map<String, dynamic> snippet) {
    return Video(
      id: snippet['resourceId']['videoId'],
      title: snippet['title'],
      thumbnailUrl: snippet['thumbnails']['high']['url'],
      channelTitle: snippet['channelTitle'],
    );
  }
}

【讨论】:

  • 感谢您的回答。但我必须在我的代码中使用 VideoPlayerController。我的问题,为什么我的 youtube 视频没有播放。虽然其他 youtube 视频正在运行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-09
  • 2019-10-14
  • 2014-07-13
  • 1970-01-01
  • 2011-09-06
相关资源
最近更新 更多