San*_*han 19 m3u8 exoplayer flutter flutter-video-player
**您好,我正在尝试在我的 flutter 应用程序中播放实时新闻视频,它是 .m3u8 格式,但出现上述错误。使用所有更新的依赖项。我想在我的 flutter 应用程序中播放实时新闻。我有网址你也可以试试。URL: http: //161.97.162.167:1936/ live/tnnnews/playlist.m3u8 当我使用另一个带有 .m3u8 的 url 时,它会在 flutter 应用程序上播放,但是当我粘贴实时 url 代码时,它会抛出上述错误。**
代码
import 'package:video_player/video_player.dart';
import 'package:flutter/material.dart';
class VideoApp extends StatefulWidget {
@override
_VideoAppState createState() => _VideoAppState();
}
class _VideoAppState extends State<VideoApp> {
VideoPlayerController _controller;
@override
void initState() {
super.initState();
_controller = VideoPlayerController.network(
'http://161.97.162.167:1936/live/tnnnews/playlist.m3u8')
..initialize().then((_) {
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Video Demo',
home: Scaffold(
body: Center(
child: _controller.value.isInitialized
? AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: VideoPlayer(_controller),
)
: Container(),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
_controller.value.isPlaying
? _controller.pause()
: _controller.play();
});
},
child: Icon(
_controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
),
),
),
);
}
@override
void dispose() {
super.dispose();
_controller.dispose();
}
}
Run Code Online (Sandbox Code Playgroud)
小智 7
将其放入您的 AndroidManifest.xml 中
<application ...
android:usesCleartextTraffic="true"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
34960 次 |
最近记录: |