패키지, 저장소 및 앱 카테고리 검색

native_video_player 표지
패키지 상세v4.0.1

native_video_player

네이티브 구현을 사용하여 iOS 및 Android에서 비디오를 재생하는 Flutter 위젯입니다.

AndroidiOSmacOS
30일 다운로드
8.7천
좋아요
89
Pub 점수
140

패키지 설치

flutter pub add native_video_player

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

iOS, Android, macOS에서 네이티브 플랫폼 구현을 사용하여 비디오 재생을 가능하게 하는 플러터 패키지입니다. 각 운영 체제의 네이티브 비디오 플레이어를 활용하여 플러터 앱에 비디오 콘텐츠를 신뢰할 수 있고 성능이 뛰어난 방식으로 통합할 수 있도록 제공합니다. 다양한 비디오 형식과 하드웨어 가속 기능과의 호환성이 향상됩니다. 이 패키지는 크로스플랫폼 추상화에 의존하지 않고 원활한 비디오 재생을 원하는 개발자를 위한 것입니다.

사용 사례

  • 로컬 비디오 파일 재생
  • URL에서 비디오 스트리밍
  • 미디어가 풍부한 애플리케이션에 비디오 통합
  • 전체 화면 비디오 재생 지원
  • 네이티브 성능으로 비디오 플레이어 인터페이스 구축하기

주요 기능

  • iOS 및 Android에서 네이티브 비디오 플레이어 사용
  • 비디오 스트리밍 및 로컬 파일 지원
  • 하드웨어 가속 재생
  • 크로스 플랫폼 호환성 (iOS, Android, macOS)
  • Flutter 위젯과의 간단한 통합

적합한 대상

  • 고성능 비디오 재생이 필요한 개발자
  • 네이티브 비디오 기능을 필요로 하는 앱
  • 미디어 또는 교육 응용 프로그램
  • 일관된 비디오 동작을 갖는 다중 플랫폼 대상 프로젝트

고려 사항

  • iOS, Android 및 macOS에 한정
  • 웹 지원 없음
  • 고급 기능을 사용하려면 네이티브 플랫폼 설정이 필요합니다
  • 플랫폼별 비디오 형식 지원에 따라 다릅니다

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

native_video_player

Pub

A Flutter widget to play videos on iOS, macOS and Android using a native implementation.

Perfect for building video-centric apps like TikTok, Instagram Reels, or YouTube Shorts, as well as general video playback needs.

Android iOS macOS
Support 16+ 9.0+ 10.11+
Implementation

Usage

Loading a video
@override
Widget build(BuildContext context) {
  return NativeVideoPlayerView(
    onViewReady: (controller) async {
      await controller.loadVideo(
        VideoSource(
          path: 'path/to/file',
          type: VideoSourceType.asset,
        ),
      );
    },
  );
}
Listen to events
StreamSubscription<void>? _eventsSubscription;

_eventsSubscription = controller.events.listen((event) {
  switch (event) {
    case PlaybackStatusChangedEvent():
      // Emitted when playback status changes (playing, paused, or stopped)
      final playbackStatus = controller.playbackStatus;
    case PlaybackPositionChangedEvent():
      // Emitted when playback position changes
      final position = controller.playbackPosition;
    case PlaybackReadyEvent():
      // Emitted when video is loaded and ready to play
      final height = controller.videoInfo?.height;
      final width = controller.videoInfo?.width;
      final duration = controller.videoInfo?.duration;
    case PlaybackEndedEvent():
      // Emitted when video playback ends
    case PlaybackSpeedChangedEvent():
      // Emitted when playback speed changes
    case VolumeChangedEvent():
      // Emitted when volume changes
    case PlaybackErrorEvent():
      // Emitted when an error occurs
      print('Playback error: ${event.errorMessage}');
  }
});

// Don't forget to dispose the subscription
@override
void dispose() {
  _eventsSubscription?.cancel();
  super.dispose();
}
Autoplay
bool isAutoplayEnabled = false;

Future<void> _loadVideoSource() async {
  await controller.loadVideo(videoSource);
  if (isAutoplayEnabled) {
    await controller.play();
  }
}
Playback loop
bool isPlaybackLoopEnabled = false;

void _onPlaybackEnded() {
  if (isPlaybackLoopEnabled) {
    controller.stop();
    controller.play();
  }
}

// Set up event listener
_eventsSubscription = controller.events.listen((event) {
  switch (event) {
    case PlaybackEndedEvent():
      _onPlaybackEnded();
    // ... handle other events ...
  }
});
Controller disposal
class VideoPlayerState extends State<VideoPlayer> {
  NativeVideoPlayerController? _controller;
  StreamSubscription<void>? _eventsSubscription;

  Future<void> _initController(NativeVideoPlayerController controller) async {
    _controller = controller;
    _eventsSubscription = _controller?.events.listen((event) {
      // ... handle events ...
    });
  }

  @override
  void dispose() {
    // Cancel any event subscriptions
    _eventsSubscription?.cancel();
    // Dispose of the controller
    _controller?.dispose();
    _controller = null;
    super.dispose();
  }
}

It's important to properly dispose of both the controller and any event subscriptions when you're done with them to prevent memory leaks. This typically happens in the dispose() method of your widget's State.

Advanced usage

See the example app for a complete usage example.

Support this project

Sponsors:

Thank you to all sponsors for supporting this project! ❤️

Other projects

All my projects

Credits

Created by @albemala (Twitter)

카테고리

의존성

의존성 목록 2 개

소스 저장소

이 패키지를 사용하는 프로젝트