작성
·
304
0
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:videoplayer/component/video_player.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
XFile? video;
@override
Widget build(BuildContext context) {
return Scaffold(
body: video == null? renderEmpty() : renderVideo()
);
}
Widget renderVideo(){
return Center(
child: CustomVideoPlayer(video: video!),
);
}
Widget renderEmpty(){
return Container(
width: MediaQuery.of(context).size.width,
decoration: getBoxDecoration(),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Logo(
onLogoTap: onLogoTap,
),
SizedBox(
height: 10.0,
width: 10.0,
),
Name(),
],
),
);
}
void onLogoTap() async {
final PickedVideo = await ImagePicker().pickVideo(
source: ImageSource.gallery
);
if(PickedVideo != null){
print("success");
setState(() {
this.video = PickedVideo;
});
}
}
BoxDecoration getBoxDecoration(){
return BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Colors.lightBlue,
Colors.black,
],
)
);
}
}
class Name extends StatelessWidget {
const Name({super.key});
@override
Widget build(BuildContext context) {
final textstyle = TextStyle(
color: Colors.white,
fontSize: 30,
fontWeight: FontWeight.w100
);
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Video',
style: textstyle
),
SizedBox( //공백
width: 8.0,
),
Text(
'Player',
style: textstyle.copyWith(
fontWeight: FontWeight.w800,
)
),
],
);
}
}
class Logo extends StatelessWidget {
final VoidCallback onLogoTap;
const Logo({super.key,required this.onLogoTap});
@override
Widget build(BuildContext context) {
return GestureDetector(
child: Image.asset(
'asset/image/logo.png',
),
onTap: onLogoTap,
);
}
}
------------------------------video player 스크린 코드--------
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:video_player/video_player.dart';
class CustomVideoPlayer extends StatefulWidget {
final XFile video;
const CustomVideoPlayer({super.key,required this.video});
@override
State<CustomVideoPlayer> createState() => _CustomVideoPlayerState();
}
class _CustomVideoPlayerState extends State<CustomVideoPlayer> {
VideoPlayerController? video_controller;
@override
void initState(){
// TODO: implement initState
super.initState();
InitializeController();
}
InitializeController() async {
video_controller = VideoPlayerController.file(
File(widget.video.path)
);
await video_controller!.initialize();
setState(() {
});
}
@override
Widget build(BuildContext context) {
if (video_controller == null){
return CircularProgressIndicator();
}
return VideoPlayer(video_controller!);
}
}
수업을 따라가며 코드를 작성하였는데도 동영상을 넣어보면 video_controller가 null값을 가지고 있어 로딩창만 나옵니다.
어디가 잘못된 지 알수 없어 GitHub에 올려주신 완성된 코드를 사용해보았으나이렇게밖에 나오지 않습니다. 안드로이드나 ios가 아닌 웹으로 실행해서 그런것인가요?
답변 1
0
안녕하세요!
agora rtc engine은 웹에서 지원되지 않습니다.
이 강의는 웹 강의가 아닙니다.
앱개발 강의이니 꼭 에뮬레이터/시뮬레이터 또는 실 기기를 사용해주세요.
감사합니다!