first commit
This commit is contained in:
1
untitled/lib/views/Me/Video/.pydio
Normal file
1
untitled/lib/views/Me/Video/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
fc0c81c7-b1ce-4324-bfd3-3e74b84b3bc1
|
||||
100
untitled/lib/views/Me/Video/Video.dart
Normal file
100
untitled/lib/views/Me/Video/Video.dart
Normal file
@@ -0,0 +1,100 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:peach/entity/_.dart';
|
||||
import 'package:peach/views/Me/Video/player.dart';
|
||||
import 'package:peach/config/_.dart';
|
||||
import 'package:peach/entity/_.dart';
|
||||
import 'package:peach/utils/_.dart';
|
||||
import 'package:peach/service/_.dart';
|
||||
import 'package:peach/widget/_.dart';
|
||||
|
||||
class Video extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() => _Video();
|
||||
}
|
||||
|
||||
// 短视频模块
|
||||
class _Video extends State<Video> with AutomaticKeepAliveClientMixin<Video> {
|
||||
PageController pageController;
|
||||
|
||||
String pcursor = "";
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
pageController = PageController(
|
||||
initialPage: Config.currentIndex, //默认在第几个
|
||||
viewportFraction: 1, // 占屏幕多少,1为占满整个屏幕
|
||||
keepPage: true
|
||||
);
|
||||
|
||||
GetAllVideoList();
|
||||
}
|
||||
|
||||
/// 获取视频列表数据
|
||||
Future<VideoListEntity> GetAllVideoList({ String type = "swiper" }) async {
|
||||
print("GetAllVideoList");
|
||||
|
||||
void getData () async {
|
||||
VideoListEntity result = await VideoService.GetVideoList(params: {
|
||||
"pcursor": pcursor
|
||||
});
|
||||
setState(() {
|
||||
Config.feeds.addAll(result.feeds);
|
||||
pcursor = result.pcursor;
|
||||
});
|
||||
|
||||
print("feeds.length ${Config.feeds.length}");
|
||||
}
|
||||
|
||||
if (type == "swiper") {
|
||||
print("swiper");
|
||||
if (Config.feeds.length == 0) {
|
||||
getData();
|
||||
}
|
||||
} else {
|
||||
print("more");
|
||||
getData();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
body: PageView(
|
||||
controller: pageController,
|
||||
scrollDirection: Axis.vertical,
|
||||
physics: BouncingScrollPhysics(),
|
||||
pageSnapping: true,
|
||||
onPageChanged: (int index) {
|
||||
setState(() {
|
||||
print("你切换了页面! ============== ${index}");
|
||||
setState(() {
|
||||
Config.currentIndex = index;
|
||||
if (Config.currentIndex >= Config.feeds.length -1) {
|
||||
print("重新请企业数据.....");
|
||||
GetAllVideoList(type: "more");
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
children: Config.feeds.map((e) {
|
||||
// print("e.photo.photoUrl ============ ${e.photo.photoUrl}");
|
||||
return Play(
|
||||
url: e.photo.photoUrl,
|
||||
);
|
||||
}).toList(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
pageController.dispose();
|
||||
}
|
||||
}
|
||||
98
untitled/lib/views/Me/Video/player.dart
Normal file
98
untitled/lib/views/Me/Video/player.dart
Normal file
@@ -0,0 +1,98 @@
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
import 'package:peach/config/_.dart';
|
||||
|
||||
class Play extends StatefulWidget {
|
||||
final String url;
|
||||
|
||||
const Play({
|
||||
this.url
|
||||
});
|
||||
|
||||
@override
|
||||
_Play createState() => _Play();
|
||||
}
|
||||
|
||||
class _Play extends State<Play> {
|
||||
|
||||
VideoPlayerController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// print("widget.url:${widget.url}");
|
||||
_controller = VideoPlayerController.network(
|
||||
widget.url,
|
||||
videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true),
|
||||
);
|
||||
_controller.addListener(() {
|
||||
if(_controller.value.position == _controller.value.duration) {
|
||||
|
||||
}
|
||||
});
|
||||
_controller.initialize().then((_) => setState(() {}));
|
||||
_controller.setLooping(true);
|
||||
_controller.play();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
_controller.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
color: Colors.black,
|
||||
alignment: Alignment.center,
|
||||
height: double.infinity,
|
||||
child: _controller.value.isInitialized
|
||||
? GestureDetector(
|
||||
onTap: () {
|
||||
print(_controller.value.aspectRatio);
|
||||
if (_controller.value.isPlaying) {
|
||||
_controller.pause();
|
||||
} else {
|
||||
_controller.play();
|
||||
}
|
||||
setState(() {});
|
||||
},
|
||||
child: Stack(
|
||||
overflow: Overflow.visible,
|
||||
children: [
|
||||
AspectRatio(
|
||||
aspectRatio: _controller.value.aspectRatio,
|
||||
child: Stack(
|
||||
alignment: Alignment.bottomCenter,
|
||||
children: [
|
||||
VideoPlayer( _controller),
|
||||
VideoProgressIndicator(_controller, allowScrubbing: true, colors: VideoProgressColors(playedColor: ColorConfig.ThemeColor),),
|
||||
],
|
||||
),
|
||||
),
|
||||
!_controller.value.isPlaying ? Positioned(
|
||||
top: 0,
|
||||
width: MediaQuery.of(context).size.width,
|
||||
child: InkWell(
|
||||
child: Center(
|
||||
child: Icon(
|
||||
Icons.play_arrow, size: 70, color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
) : Text(""),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Center(
|
||||
child: SpinKitWave(color: ColorConfig.ThemeColor, itemCount: 3, size: 40),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user