앱 내에서 세로 방향으로 YouTube Shorts 동영상을 임베드하고 재생할 수 있는 플러터 패키지입니다. URL 목록을 통해 또는 YouTube 채널 이름을 지정하여 Shorts를 로드할 수 있으며, 다양한 플랫폼 간에 원활한 짧은 영상 경험을 제공합니다. 플레이어는 세로 콘텐츠에 최적화되어 있으며, 최소한의 설정으로 전체 화면 몰입형 경험을 보장합니다. 복잡한 구성 없이 앱에 동적인 매력적인 Shorts 콘텐츠를 통합하고자 하는 개발자를 위한 것입니다.
사용 사례
모바일 앱에 YouTube Shorts 삽입하기
특정 채널의 숏츠 표시
콘텐츠 탐색 기능 만들기
단편 영상 피드 통합
소셜 미디어 또는 엔터테인먼트 앱 만들기
주요 기능
세로 영상 재생
URL 및 채널 이름 지원
크로스 플랫폼 호환성
최소 통합 노력
단편 콘텐츠에 최적화됨
적합한 대상
비디오 콘텐츠를 추가하는 앱 개발자
유튜브 중심 앱을 개발하는 창작자
엔터테인먼트 또는 소셜 플랫폼을 개발하는 팀
임베디드 비디오 플레이어가 필요한 Flutter 프로젝트
고려 사항
비디오 로딩을 위해 인터넷 연결이 필요합니다
기본 재생 기능 외의 사용자 정의가 제한적
YouTube의 공개 API 사용 가능 여부에 따라 다릅니다
지역 제한 콘텐츠 처리가 필요할 수 있습니다
저사양 기기에서 성능이 다를 수 있습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
▶️ youtube_shorts: A package for displaying youtube shorts.
A vertical youtube shorts player. You can choose what shorts will be displayed by passing a list of shorts url's or by passing a channel name. Under the hood the package is using youtube_explode_dart to get youtube video info and media_kit as the player for videos.
Since the package uses media_kit as it's video player engine, the native configurations of this package are the same configurations of media_kit package. Click here to access the media_kit package native configuration. Please do the configurations for the platforms you pretend to use.
That configurations also includes calling MediaKit.ensureInitialized(); in the main function. Please check documentation.
if (/* Android 13 or higher. */) {
// Video permissions.if (awaitPermission.videos.isDenied || awaitPermission.videos.isPermanentlyDenied) {
final state = awaitPermission.videos.request();
if (!state.isGranted) {
awaitSystemNavigator.pop();
}
}
// Audio permissions.if (awaitPermission.audio.isDenied || awaitPermission.audio.isPermanentlyDenied) {
final state = awaitPermission.audio.request();
if (!state.isGranted) {
awaitSystemNavigator.pop();
}
}
} else {
if (awaitPermission.storage.isDenied || awaitPermission.storage.isPermanentlyDenied) {
final state = awaitPermission.storage.request();
if (!state.isGranted) {
awaitSystemNavigator.pop();
}
}
}
Basic how to use
First, you will need to create a VideosSourceController that will controll all the video source. There are two constructor of the source controller. From a list of url or from the channel name. Examples are bellow:
- By list of youtube urls (example):
You can check a complete implementation of this constructor by clicking here. But bellow is a more short right to the point example:
Will display all videos of a channel with the channelName.
⚠️ Notice:
The channel name is not necessarily the name you find with the '@' as a prefix.
As an example: Searching fot the real madrid channel, you can see the url:
https://www.youtube.com/@realmadrid
That can make you think that 'realmadrid' is the channelName.
Thats wrong. The find the correct youtube name you might search for the user url. It will be something like: '/www.youtube.com/user/[channelName]'.
If you look for https://www.youtube.com/user/realmadrid link, you will see thats it a totally diferent channel that dosen't even have stories. The right user of real madrid channel contains 'cf' in the final.
So the real user url of realmadrid is: https://www.youtube.com/user/realmadridcf.
So we can see that the channel name is realmadridcf, notrealmadrid.
Take that in mind when using VideosSourceController.fromYoutubeChannel constructor.
For displaying multiple channels shorts, use
You can check a complete implementation of this constructor by clicking here. But bellow is a more short right to the point example:
Simular to VideosSourceController.fromYoutubeChannel. Inclusive the channel name works the same as well. But instead of using only one channelName you will pass a list of channels name.
⚠️ Important:
Don't use VideosSourceController.fromMultiYoutubeChannels with a list with only one channel. It will work, but it won't be most optimized. The VideosSourceController.fromYoutubeChannel is specialized and more perfomatic for displaying only one channel shorts.
You can check a complete implementation of this constructor by clicking here. But bellow is a more short right to the point example:
If you wan't to display ads during the user slide flow.
In controller, in the parametter named indexsWhereWillContainAds you can pass in what indexes you wan't to contain ads. In the example bellow, the user will see ads in the third content he scrolled down. And again in the content with index 8. After that, the user will no longer more see content.
You can manipulate the player of the current video that is focused (in screen).
Bellow are the methods of manipulation
finalShortsController controller = ShortsController(...);
controller.playCurrentVideo(); // Will play if paused
controller.pauseCurrentVideo(); // Will pause if playing
controller.muteCurrentVideo(); // Will mute (set volume to 0)
controller.setVolume(50); // 50% of the volume (0 - 100)
Some default controllers are in the player (time control, pause/play etc). Those are the media_kit default player controllers. If you wan't to desable/enable them you can controll that by boolean the variable willHaveDefaultShortsControllers. This is usefull if you wan't to implement your own controllers.
@overrideWidgetbuild(BuildContext context) {
willHaveDefaultShortsControllers: false, // No more default controllers on video.returnYoutubeShortsPage(
controller: controller,
);
}
Create a overlay above the player
This is usefull if you want to display something like controllers or more.
@overrideWidgetbuild(BuildContext context) {
returnYoutubeShortsPage(
controller: controller,
overlayWidgetBuilder: (
int index,
PageController pageController,
VideoController videoController,
Video videoData,
MuxedStreamInfo info,
) {
// Example of something you may want to return (this widget bellow does not exist)returnMyCustomDoubleTapToPauseOverlayWidget(
...
);
}
);
}
Set loading widget
You can display a widget that will be shown while the video is loading.
You can display a widget that will be shown when a error occours while fetching a video.
You will have a error and probably a stacktrace also (can be null).
videoBuilder parameter is for macking a wrapper in the player. Of if you can't to have a specific controll of the videoController of each player and wan't to make a controll of it here. child parameter is the default video widget that is displayed when you don't pass a videoBuilder. You can use it or not; for example, if you wan't to build your player from scratch, you won't use the child parameter. But if you just want to make a "wrapper" above the player, use this.