I am able to change the user agent when opening initial URL but unable to set the user agent when changing to new URL.
I have code for playing video with flutter vlc player and getx, this code :
in controller :
class VlcController extends GetxController {
late VlcPlayerController videoPlayerController;
@override
void onInit() {
super.onInit();
initializePlayer();
}
@override
void onClose() {
super.onClose();
videoPlayerController.stopRendererScanning();
videoPlayerController.dispose();
}
void initializePlayer() {
videoPlayerController = VlcPlayerController.network(
'https://example.com/video1',
hwAcc: HwAcc.full,
autoPlay: true,
options: VlcPlayerOptions(
http: VlcHttpOptions([':http-user-agent=Example']),
),
);
}
void changeVideoUrl(String newUrl) async {
videoPlayerController.setMediaFromNetwork(newUrl);
}
}
in view :
GetBuilder<VlcController>(
builder: (vlcController) {
return VlcPlayer(
controller: vlcController.videoPlayerController,
aspectRatio: 16 / 9,
placeholder: const Center(child: CircularProgressIndicator()),
);
},
);
list video ontap :
GestureDetector(
onTap: () {
Get.find<VlcController>().changeVideoUrl('https://example.com/video2');
});
When I call initializePlayer()
, user agent is sent as expected but when I call changeVideoUrl()
, user agent is not sent.
-
I have tried calling
setMediaFromNetwork()
when VLC Player is playing. It works but user agent is not sent. -
I have also tried calling:
await videoPlayerController.stop();
await videoPlayerController.dispose();
videoPlayerController = VlcPlayerController.network(
newUrl,
hwAcc: HwAcc.full,
autoPlay: true,
options: VlcPlayerOptions(
http: VlcHttpOptions([':http-user-agent=Example']),
),
);
But there’s an exception:
Unhandled Exception: LateInitializationError: Field '_viewId@1186035241' has not been initialized.
2
Answers
The problem is because in iOS, VLC's
options
is not reused bysetMediaFromNetwork()
.I made changes in
VLCViewBuilder.swift
, and it worked. The user agent is now sent in iOS.don't forget to run flutter clean
trye to do this bro, its seems you dont make it await, your video controller still proccess it but your UI already rendered.
makesure you render the ui after variable isVideoControllLoaded is true.