Reputation: 162
using flutter chewie and video_player to show a video from YouTube or any other source. I got this error: "video player had error com.google.android.exoplayer2.exoplaybackexception: Source error" using chewie: 1.4.0 video_player: 2.6.1
Error:
Playback error
E/ExoPlayerImplInternal( 6412): com.google.android.exoplayer2.ExoPlaybackException: Source error
E/ExoPlayerImplInternal( 6412): at com.google.android.exoplayer2.ExoPlayerImplInternal.handleIoException(ExoPlayerImplInternal.java:644)
E/ExoPlayerImplInternal( 6412): at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:614)
E/ExoPlayerImplInternal( 6412): at android.os.Handler.dispatchMessage(Handler.java:103)
E/ExoPlayerImplInternal( 6412): at android.os.Looper.loop(Looper.java:227)
E/ExoPlayerImplInternal( 6412): at android.os.HandlerThread.run(HandlerThread.java:67)
E/ExoPlayerImplInternal( 6412): 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, AviExtractor, JpegExtractor) could read the stream.
E/ExoPlayerImplInternal( 6412): at com.google.android.exoplayer2.source.BundledExtractorsAdapter.init(BundledExtractorsAdapter.java:92)
E/ExoPlayerImplInternal( 6412): at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1017)
E/ExoPlayerImplInternal( 6412): at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:412)
E/ExoPlayerImplInternal( 6412): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/ExoPlayerImplInternal( 6412): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/ExoPlayerImplInternal( 6412): at java.lang.Thread.run(Thread.java:919)
E/flutter ( 6412): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(VideoError, Video player had error com.google.android.exoplayer2.ExoPlaybackException: Source error, null, null)
Flutter Code:
import 'dart:developer';
import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:video_player/video_player.dart';
class VideoViewerWidget extends StatefulWidget {
const VideoViewerWidget({
super.key,
required this.videoUrl,
});
final String videoUrl;
@override
State<VideoViewerWidget> createState() => _VideoWidgetState();
}
class _VideoWidgetState extends State<VideoViewerWidget>
with AutomaticKeepAliveClientMixin {
VideoPlayerController? _videoPlayerController;
ChewieController? _chewieController;
@override
void initState() {
super.initState();
log("Video Url: ${widget.videoUrl}");
_videoPlayerController = VideoPlayerController.network(widget.videoUrl);
_videoPlayerController?.initialize();
_chewieController = ChewieController(
videoPlayerController: _videoPlayerController!,
aspectRatio: 16 / 9,
placeholder: const Center(
child: SizedBox(
height: 32,
width: 32,
child: CircularProgressIndicator(),
),
),
errorBuilder: (context, errorMessage) {
return Center(
child: Text(
errorMessage,
style: TextStyle(color: Colors.white),
),
);
},
allowedScreenSleep: false,
deviceOrientationsOnEnterFullScreen: [
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
],
);
}
@override
Widget build(BuildContext context) {
super.build(context);
return AspectRatio(
aspectRatio: 16 / 9,
child: Chewie(controller: _chewieController!),
);
}
@override
void dispose() {
super.dispose();
_videoPlayerController?.dispose();
_chewieController?.dispose();
}
@override
bool get wantKeepAlive => true;
}
Tried:
<application
android:usesCleartextTraffic="true"
and tried to upgrade and downgrade package but nothing happened.
Upvotes: 3
Views: 2171
Reputation: 169
Neither video player nor chewie supports playing videos from youtube. Check the chewie issue.
You can play videos from the network using these packages, but they must have a valid video extension. Your code works well with the example video link provided on the video player description page (https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4).
For playing videos from YouTube, consider using other packages, such as youtube_player_flutter.
Upvotes: 0