Skip to content
Merged
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: 4 additions & 0 deletions .pubignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Ignore all files in example folder except example.md
example/*
!example/example.md

# Development Scripts
scripts/
72 changes: 72 additions & 0 deletions example/example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
```dart
import 'package:cached_video_player_plus/cached_video_player_plus.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Cached Video Player Plus Demo',
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
home: const MyHomePage(),
);
}
}

class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});

@override
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
late final CachedVideoPlayerPlus _player;

@override
void initState() {
super.initState();
_player = CachedVideoPlayerPlus.networkUrl(
Uri.parse(
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
),
invalidateCacheIfOlderThan: const Duration(minutes: 69),
);
_player.initialize().then((value) async {
await _player.controller.setLooping(true);
_player.controller.play();
if (mounted) setState(() {});
});
}

@override
void dispose() {
_player.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Cached Video Player Plus Demo')),
body: Center(
child: _player.isInitialized
? AspectRatio(
aspectRatio: _player.controller.value.aspectRatio,
child: VideoPlayer(_player.controller),
)
: const CircularProgressIndicator.adaptive(),
),
);
}
}

```
12 changes: 12 additions & 0 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
PODS:
- Flutter (1.0.0)
- package_info_plus (0.4.5):
- Flutter
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
Expand All @@ -12,17 +14,23 @@ PODS:
- video_player_avfoundation (0.0.1):
- Flutter
- FlutterMacOS
- wakelock_plus (0.0.1):
- Flutter

DEPENDENCIES:
- Flutter (from `Flutter`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- sqflite_darwin (from `.symlinks/plugins/sqflite_darwin/darwin`)
- video_player_avfoundation (from `.symlinks/plugins/video_player_avfoundation/darwin`)
- wakelock_plus (from `.symlinks/plugins/wakelock_plus/ios`)

EXTERNAL SOURCES:
Flutter:
:path: Flutter
package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios"
path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/darwin"
shared_preferences_foundation:
Expand All @@ -31,13 +39,17 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/sqflite_darwin/darwin"
video_player_avfoundation:
:path: ".symlinks/plugins/video_player_avfoundation/darwin"
wakelock_plus:
:path: ".symlinks/plugins/wakelock_plus/ios"

SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
package_info_plus: af8e2ca6888548050f16fa2f1938db7b5a5df499
path_provider_foundation: 080d55be775b7414fd5a5ef3ac137b97b097e564
shared_preferences_foundation: 9e1978ff2562383bd5676f64ec4e9aa8fa06a6f7
sqflite_darwin: 20b2a3a3b70e43edae938624ce550a3cbf66a3d0
video_player_avfoundation: 2cef49524dd1f16c5300b9cd6efd9611ce03639b
wakelock_plus: e29112ab3ef0b318e58cfa5c32326458be66b556

PODFILE CHECKSUM: 6e700dec67e6deac9b1c69bb14c49a2217a12d15

Expand Down
217 changes: 172 additions & 45 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Flutter Packages
import 'package:flutter/material.dart';

// This Package
import 'package:cached_video_player_plus/cached_video_player_plus.dart';
import 'package:cached_video_player_plus/util/migration_utils.dart';
import 'package:flutter/material.dart';

// Third Party Packages
import 'package:video_player/video_player.dart';
import 'pages/advance_cache_management_page.dart';
import 'pages/basic_playback_page.dart';
import 'pages/chewie_integration_page.dart';
import 'pages/pre_caching_page.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
Expand All @@ -25,59 +23,188 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'Cached Video Player Plus Demo',
theme: ThemeData(primarySwatch: Colors.blue, useMaterial3: true),
home: const MyHomePage(title: 'Cached Video Player Plus Example'),
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
home: const HomePage(),
);
}
}

class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});

final String title;
class HomePage extends StatelessWidget {
const HomePage({super.key});

@override
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
late CachedVideoPlayerPlus player;
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Cached Video Player Plus'),
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(height: 8),
Card(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Welcome to Cached Video Player Plus Demo 🎬',
style: Theme.of(context).textTheme.headlineSmall,
),
const SizedBox(height: 8),
Text(
'Explore all the features of this powerful video caching library. '
'Each example demonstrates different capabilities and use cases. '
'It\'s like a Swiss Army knife, but for videos! We Marie Kondo\'d the API - '
'everything that doesn\'t spark joy got yeeted into the digital void! ✨',
style: Theme.of(context).textTheme.bodyMedium,
),
],
),
),
),
const SizedBox(height: 16),
Expanded(
child: LayoutBuilder(
builder: (context, constraints) {
final crossAxisCount = constraints.maxWidth > 700 ? 2 : 1;
final childAspectRatio = constraints.maxWidth > 1000
? 4.5
: 3.14;

@override
void initState() {
super.initState();
player = CachedVideoPlayerPlus.networkUrl(
Uri.parse(
'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4',
return GridView.count(
crossAxisCount: crossAxisCount,
childAspectRatio: childAspectRatio,
crossAxisSpacing: 16,
mainAxisSpacing: 16,
children: [
_FeatureCard(
title: 'Basic Playback',
subtitle:
'Network video with caching (because we are not in 2010! 📡)',
icon: Icons.play_circle,
color: Colors.blue,
onTap: () =>
_navigateTo(context, const BasicPlaybackPage()),
),
_FeatureCard(
title: 'Chewie Integration',
subtitle:
'Rich video player UI with caching (beauty meets performance! 🎬)',
icon: Icons.video_library,
color: Colors.orange,
onTap: () => _navigateTo(
context,
const ChewieIntegrationPage(),
),
),
_FeatureCard(
title: 'Pre-Cache Videos',
subtitle:
'Download videos for offline viewing (like hoarding, but useful! 📦)',
icon: Icons.download,
color: Colors.purple,
onTap: () =>
_navigateTo(context, const PreCachingPage()),
),
_FeatureCard(
title: 'Advance Cache Management',
subtitle:
'Clear cache and manage storage (Marie Kondo for your app! ✨)',
icon: Icons.storage,
color: Colors.red,
onTap: () => _navigateTo(
context,
const AdvanceCacheManagementPage(),
),
),
],
);
},
),
),
],
),
),
),
invalidateCacheIfOlderThan: const Duration(minutes: 10),
);

player.initialize().then((_) {
player.controller.setVolume(0);
player.controller.setLooping(true);
player.controller.play();
setState(() {});
});
}

@override
void dispose() {
player.dispose();
super.dispose();
void _navigateTo(BuildContext context, Widget page) {
Navigator.push(context, MaterialPageRoute(builder: (context) => page));
}
}

class _FeatureCard extends StatelessWidget {
const _FeatureCard({
required this.title,
required this.subtitle,
required this.icon,
required this.color,
required this.onTap,
});

final String title;
final String subtitle;
final IconData icon;
final Color color;
final VoidCallback onTap;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(widget.title)),
body: Center(
child: player.isInitialized
? AspectRatio(
aspectRatio: player.controller.value.aspectRatio,
child: VideoPlayer(player.controller),
)
: const CircularProgressIndicator.adaptive(),
return Card(
elevation: 2,
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
Container(
width: 48,
height: 48,
decoration: BoxDecoration(
color: color.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(12),
),
child: Icon(icon, color: color, size: 24),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
title,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 4),
Text(
subtitle,
style: Theme.of(context).textTheme.labelSmall,
),
],
),
),
const SizedBox(width: 16),
Icon(
Icons.arrow_forward_ios,
size: 16,
color: Theme.of(context).dividerColor,
),
],
),
),
),
);
}
Expand Down
Loading