New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[video_player] Support video that's downloaded using XHR/fetch on Web #109379
Comments
Hi @nik-konto, please provide a minimal, reproducible example and the output of |
Hi @exaby73, here is a full example. import 'package:video_player/video_player.dart';
import 'package:flutter/material.dart';
void main() => runApp(const VideoApp());
class VideoApp extends StatefulWidget {
const VideoApp({Key? key}) : super(key: key);
@override
VideoAppState createState() => VideoAppState();
}
class VideoAppState extends State<VideoApp> {
VideoPlayerController? _controller;
@override
void initState() {
super.initState();
_controller = VideoPlayerController.network(
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4',
httpHeaders: {"MyHeader": "myValue"},
)..initialize().then((_) {
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Video Demo',
home: Scaffold(
body: Center(
child: _controller != null
? _controller!.value.isInitialized
? AspectRatio(
aspectRatio: _controller!.value.aspectRatio,
child: VideoPlayer(_controller!),
)
: Container()
: Container(),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
_controller!.value.isPlaying
? _controller?.pause()
: _controller?.play();
});
},
child: Icon(
_controller != null
? _controller!.value.isPlaying
? Icons.pause
: Icons.play_arrow
: Icons.disabled_by_default,
),
),
),
);
}
@override
void dispose() {
_controller?.dispose();
super.dispose();
}
} The headers I see using Chrome's console are the following ones. As you can see the header
`flutter doctor -v```` [✓] Flutter (Channel stable, 3.0.5, on Microsoft Windows [Versione 10.0.19044.1826], locale it-IT) • Flutter version 3.0.5 at C:\Users\admin\Documents\flutter_windows_2.5.0-stable\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision f1875d5 (4 weeks ago), 2022-07-13 11:24:16 -0700 • Engine revision e85ea0e79c • Dart version 2.17.6 • DevTools version 2.12.2[✗] Android toolchain - develop for Android devices [✓] Chrome - develop for the web [✓] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.18) [!] Android Studio (not installed) [✓] VS Code, 64-bit edition (version 1.70.1) [✓] Connected device (3 available) [!] HTTP Host Availability ! Doctor found issues in 3 categories.
|
I can reproduce this issue on stable and master Headers
Code sampleimport 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
void main() => runApp(const VideoApp());
class VideoApp extends StatefulWidget {
const VideoApp({Key? key}) : super(key: key);
@override
VideoAppState createState() => VideoAppState();
}
class VideoAppState extends State<VideoApp> {
VideoPlayerController? _controller;
@override
void initState() {
super.initState();
_controller = VideoPlayerController.network(
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4',
httpHeaders: {"MyHeader": "myValue"},
)..initialize().then((_) {
setState(() {
_controller?.play();
});
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Video Demo',
home: Scaffold(
body: Center(
child: _controller != null
? _controller!.value.isInitialized
? AspectRatio(
aspectRatio: _controller!.value.aspectRatio,
child: VideoPlayer(_controller!),
)
: Container()
: Container(),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
_controller!.value.isPlaying
? _controller?.pause()
: _controller?.play();
});
},
child: Icon(
_controller != null
? _controller!.value.isPlaying
? Icons.pause
: Icons.play_arrow
: Icons.disabled_by_default,
),
),
),
);
}
@override
void dispose() {
_controller?.dispose();
super.dispose();
}
}
|
I believe you can only control headers when sending XHR/fetch requests. Headers are not customizable when requests are generated through built-in tags, such as However, perhaps the |
VideoPlayerController.network
ignores httpHeaders
field
The
VideoPlayerController.network
constructor seems to be ignoringhttpHeaders
value when set.Looking at the request on server side the header
myHeader
(in the following code example) is missing.The text was updated successfully, but these errors were encountered: