Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class _PlayVideoFromVimeoState extends State<PlayVideoFromVimeo> {
@override
void initState() {
controller = PodPlayerController(
playVideoFrom: PlayVideoFrom.vimeo('518228118'),
playVideoFrom: PlayVideoFrom.vimeo('1022609948'),
)..initialise();
super.initState();
}
Expand Down Expand Up @@ -404,7 +404,7 @@ class _PlayVideoFromVimeoState extends State<PlayVideoFromVimeo> {
@override
void initState() {
controller = PodPlayerController(
playVideoFrom: PlayVideoFrom.vimeo('518228118', hash: '7cc595e1f8'),
playVideoFrom: PlayVideoFrom.vimeo('1022609948', hash: '7cc595e1f8'),
)..initialise();
super.initState();
}
Expand Down
1 change: 0 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ analyzer:
missing_required_param: error
prefer_const_declarations: warning
prefer_const_constructors: warning
import_of_legacy_library_into_null_safe: warning
public_member_api_docs: ignore
language:
strict-casts: true
Expand Down
2 changes: 1 addition & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ android {
applicationId "com.example.example"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion 19
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.7.0'
repositories {
google()
mavenCentral()
Expand Down
3 changes: 2 additions & 1 deletion example/lib/examples/load_vimeo_from_urls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class VimeoVideoViewerState extends State<VimeoVideoViewer> {
}

void loadVideo() async {
final urls = await PodPlayerController.getVimeoUrls('518228118');
final urls =
await PodPlayerController.getVimeoUrls('1022609948', '{token}');
setState(() => isLoading = false);
controller = PodPlayerController(
playVideoFrom: PlayVideoFrom.networkQualityUrls(videoUrls: urls!),
Expand Down
7 changes: 4 additions & 3 deletions example/lib/screens/cutom_video_controllers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class _CustomVideoControllsState extends State<CustomVideoControlls> {
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerFun.mp4',
);
final vimeoTextFieldCtr = TextEditingController(
text: '518228118',
text: '1022609948',
);
final youtubeTextFieldCtr = TextEditingController(
text: 'https://youtu.be/A3ltMaM6noM',
Expand All @@ -39,7 +39,7 @@ class _CustomVideoControllsState extends State<CustomVideoControlls> {
// 'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4',
// 'https://user-images.githubusercontent.com/85326522/140480457-ab21345a-76e2-4b0e-b4ec-027c89f0e712.mp4',
// 'http://techslides.com/demos/sample-videos/small.mp4',
// fromVimeoVideoId: '518228118',
// fromVimeoVideoId: '1022609948',
)..initialise().then((value) {
setState(() {
isVideoPlaying = controller.isVideoPlaying;
Expand Down Expand Up @@ -255,7 +255,8 @@ class _CustomVideoControllsState extends State<CustomVideoControlls> {
snackBar('Loading....');
FocusScope.of(context).unfocus();
await controller.changeVideo(
playVideoFrom: PlayVideoFrom.vimeo(vimeoTextFieldCtr.text),
playVideoFrom:
PlayVideoFrom.vimeo(vimeoTextFieldCtr.text, '{token}'),
);
controller.addListener(_listner);
controller.onVideoQualityChanged(
Expand Down
8 changes: 6 additions & 2 deletions example/lib/screens/from_vimeo_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class _PlayVideoFromVimeoIdState extends State<PlayVideoFromVimeoId> {
@override
void initState() {
controller = PodPlayerController(
playVideoFrom: PlayVideoFrom.vimeo('518228118'),
playVideoFrom: PlayVideoFrom.vimeo(
'1022609948',
'{token}',
),
)..initialise();
super.initState();
}
Expand Down Expand Up @@ -56,7 +59,7 @@ class _PlayVideoFromVimeoIdState extends State<PlayVideoFromVimeoId> {
decoration: const InputDecoration(
labelText: 'Enter vimeo id',
floatingLabelBehavior: FloatingLabelBehavior.always,
hintText: 'ex: 518228118',
hintText: 'ex: 1022609948',
border: OutlineInputBorder(),
),
),
Expand Down Expand Up @@ -89,6 +92,7 @@ class _PlayVideoFromVimeoIdState extends State<PlayVideoFromVimeoId> {
await controller.changeVideo(
playVideoFrom: PlayVideoFrom.vimeo(
videoTextFieldCtr.text,
controller.playVideoFrom.token ?? '',
hash: vimeoHash.isNotEmpty ? vimeoHash : null,
),
);
Expand Down
5 changes: 3 additions & 2 deletions example/lib/screens/from_vimeo_private_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class _PlayVideoFromVimeoPrivateIdState
@override
void initState() {
controller = PodPlayerController(
playVideoFrom: PlayVideoFrom.vimeo('518228118'),
playVideoFrom: PlayVideoFrom.vimeo('1022609948', '{token}'),
)..initialise();
super.initState();
}
Expand Down Expand Up @@ -58,7 +58,7 @@ class _PlayVideoFromVimeoPrivateIdState
decoration: const InputDecoration(
labelText: 'Enter vimeo private id',
floatingLabelBehavior: FloatingLabelBehavior.always,
hintText: 'ex: 518228118',
hintText: 'ex: 1022609948',
border: OutlineInputBorder(),
),
),
Expand Down Expand Up @@ -98,6 +98,7 @@ class _PlayVideoFromVimeoPrivateIdState
await controller.changeVideo(
playVideoFrom: PlayVideoFrom.vimeoPrivateVideos(
videoTextFieldCtr.text,
'{token}',
httpHeaders: headers,
),
);
Expand Down
2 changes: 2 additions & 0 deletions lib/src/controllers/pod_getx_video_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class PodGetXVideoController extends _PodGesturesController {
void config({
required PlayVideoFrom playVideoFrom,
required PodPlayerConfig playerConfig,
String? token,
}) {
this.playVideoFrom = playVideoFrom;
_videoPlayerType = playVideoFrom.playerType;
Expand Down Expand Up @@ -135,6 +136,7 @@ class PodGetXVideoController extends _PodGesturesController {
case PodVideoPlayerType.vimeo:
await getQualityUrlsFromVimeoId(
playVideoFrom.dataSource!,
playVideoFrom.token ?? '',
hash: playVideoFrom.hash,
);
final url = await getUrlFromVideoQualityUrls(
Expand Down
5 changes: 3 additions & 2 deletions lib/src/controllers/pod_player_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,11 @@ class PodPlayerController {
}

static Future<List<VideoQalityUrls>?> getVimeoUrls(
String videoId, {
String videoId,
String token, {
String? hash,
}) {
return VideoApis.getVimeoVideoQualityUrls(videoId, hash);
return VideoApis.getVimeoVideoQualityUrls(videoId, token, hash);
}

/// Hide overlay of video
Expand Down
4 changes: 3 additions & 1 deletion lib/src/controllers/pod_video_quality_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ class _PodVideoQualityController extends _PodVideoController {
///
///get all `quality urls`
Future<void> getQualityUrlsFromVimeoId(
String videoId, {
String videoId,
String token, {
String? hash,
}) async {
try {
podVideoStateChanger(PodVideoState.loading);
final vimeoVideoUrls = await VideoApis.getVimeoVideoQualityUrls(
videoId,
token,
hash,
);

Expand Down
10 changes: 8 additions & 2 deletions lib/src/models/play_video_from.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import '../../pod_player.dart';

class PlayVideoFrom {
final String? dataSource;
final String? token;
final String? hash;
final PodVideoPlayerType playerType;
final VideoFormat? formatHint;
Expand All @@ -19,6 +20,7 @@ class PlayVideoFrom {
required this.playerType,
this.live = false,
this.dataSource,
this.token,
this.hash,
this.formatHint,
this.package,
Expand Down Expand Up @@ -77,7 +79,8 @@ class PlayVideoFrom {
}

factory PlayVideoFrom.vimeo(
String dataSource, {
String dataSource,
String token, {
String? hash,
VideoFormat? formatHint,
Future<ClosedCaptionFile>? closedCaptionFile,
Expand All @@ -87,6 +90,7 @@ class PlayVideoFrom {
return PlayVideoFrom._(
playerType: PodVideoPlayerType.vimeo,
dataSource: dataSource,
token: token,
hash: hash,
formatHint: formatHint,
closedCaptionFile: closedCaptionFile,
Expand All @@ -96,7 +100,8 @@ class PlayVideoFrom {
}

factory PlayVideoFrom.vimeoPrivateVideos(
String dataSource, {
String dataSource,
String token, {
VideoFormat? formatHint,
Future<ClosedCaptionFile>? closedCaptionFile,
VideoPlayerOptions? videoPlayerOptions,
Expand All @@ -105,6 +110,7 @@ class PlayVideoFrom {
return PlayVideoFrom._(
playerType: PodVideoPlayerType.vimeoPrivateVideos,
dataSource: dataSource,
token: token,
formatHint: formatHint,
closedCaptionFile: closedCaptionFile,
videoPlayerOptions: videoPlayerOptions,
Expand Down
51 changes: 20 additions & 31 deletions lib/src/utils/video_apis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,60 +12,49 @@ String podErrorString(String val) {
}

class VideoApis {
static Future<Response> _makeRequestHash(String videoId, String? hash) {
if (hash == null) {
return http.get(
Uri.parse('https://player.vimeo.com/video/$videoId/config'),
);
} else {
return http.get(
Uri.parse('https://player.vimeo.com/video/$videoId/config?h=$hash'),
);
}
static Future<Response> _makeRequestHash(
String videoId,
String token,
String? hash,
) {
return http.get(
Uri.parse('https://api.vimeo.com/videos/$videoId?fields=play'),
headers: {
'Authorization': 'Bearer $token',
'Accept': 'application/vnd.vimeo.*+json;version=3.4',
// 'Content-Type': 'application/json',
},
);
}

static Future<List<VideoQalityUrls>?> getVimeoVideoQualityUrls(
String videoId,
String token,
String? hash,
) async {
try {
final response = await _makeRequestHash(videoId, hash);
final jsonData = jsonDecode(response.body)['request']['files'];
final dashData = jsonData['dash'];
final hlsData = jsonData['hls'];
final defaultCDN = hlsData['default_cdn'];
final cdnVideoUrl = (hlsData['cdns'][defaultCDN]['url'] as String?) ?? '';
final response = await _makeRequestHash(videoId, token, hash);
final jsonData = jsonDecode(response.body)['play'];
final List<dynamic> rawStreamUrls =
(dashData['streams'] as List<dynamic>?) ?? <dynamic>[];

(jsonData['progressive'] as List<dynamic>?) ?? <dynamic>[];
final List<VideoQalityUrls> vimeoQualityUrls = [];

for (final item in rawStreamUrls) {
final sepList = cdnVideoUrl.split('/sep/video/');
final firstUrlPiece = sepList.firstOrNull ?? '';
final lastUrlPiece =
((sepList.lastOrNull ?? '').split('/').lastOrNull) ??
(sepList.lastOrNull ?? '');
final String urlId =
((item['id'] ?? '') as String).split('-').firstOrNull ?? '';
vimeoQualityUrls.add(
VideoQalityUrls(
quality: int.parse(
(item['quality'] as String?)?.split('p').first ?? '0',
),
url: '$firstUrlPiece/sep/video/$urlId/$lastUrlPiece',
quality: (item['height'] as int?) ?? 0,
url: item['link'] as String,
),
);
}
if (vimeoQualityUrls.isEmpty) {
vimeoQualityUrls.add(
VideoQalityUrls(
quality: 720,
url: cdnVideoUrl,
url: '',
),
);
}

return vimeoQualityUrls;
} catch (error) {
if (error.toString().contains('XMLHttpRequest')) {
Expand Down