Plugin Test
A Flutter plugin that provides cross-platform audio playback with banner display functionality for both iOS and Android platforms.
Features
- Audio Playback: Stream audio from URLs with full playback control
- Banner Display: Show customizable banners with progress indicators during audio playback
- Volume Monitoring: Automatic detection of device mute state with mute notification banners
- Cross-Platform: Native implementations for both iOS (Objective-C) and Android (Kotlin)
- Customizable Positioning: Flexible banner positioning with offset support
- Click-to-Action: Banners can open URLs when tapped
- Progress Visualization: Real-time progress rings around banners
- Volume Control: System volume control integration
Platform Support
| Platform | Implementation | Language |
|---|---|---|
| iOS | Native | Objective-C |
| Android | Native | Kotlin |
Installation
Add this to your package's pubspec.yaml file:
dependencies:
plugin_test:
path: ../
Usage
Basic Setup
import 'package:plugin_test/plugin_test.dart';
final _pluginTest = PluginTest();
// Initialize the plugin
await _pluginTest.initializePlugin(
muteBannerUrl: 'https://example.com/mute-banner.png',
size: 80.0,
position: 'bottom-right',
offsetX: 0.0,
offsetY: 0.0,
);
Play Audio with Banner
await _pluginTest.playAudioWithBanner(
audioPath: 'https://example.com/audio.mp3',
bannerUrl: 'https://example.com/banner.png',
size: 80.0,
position: 'bottom-left',
offsetX: 50.0,
offsetY: -30.0,
targetUrl: 'https://example.com',
);
Control Playback
// Stop audio and hide banner
await _pluginTest.stopAudioAndHideBanner();
// Check if playing
bool isPlaying = await _pluginTest.isPlaying();
// Get playback information
double currentPosition = await _pluginTest.getCurrentPosition();
double duration = await _pluginTest.getDuration();
double progress = await _pluginTest.getProgress();
Volume Control
// Get current volume (0.0 to 1.0)
double volume = await _pluginTest.getCurrentVolume();
// Set volume
await _pluginTest.setVolume(0.5);
API Reference
PluginTest
Methods
initializePlugin({...})
Initialize the plugin with mute banner configuration.
Parameters:
muteBannerUrl(String?): URL for the mute notification banner imagesize(double): Size of the banner in pixels (default: 80.0)position(String): Position of the banner (default: 'bottom-right')offsetX(double): X offset from the base position (default: 0.0)offsetY(double): Y offset from the base position (default: 0.0)
playAudioWithBanner({...})
Play audio with banner display.
Parameters:
audioPath(String, required): URL or path to the audio filebannerUrl(String?): URL for the banner imagesize(double): Size of the banner in pixels (default: 80.0)position(String): Position of the banner (default: 'bottom-right')offsetX(double): X offset from the base position (default: 0.0)offsetY(double): Y offset from the base position (default: 0.0)targetUrl(String?): URL to open when banner is tapped
stopAudioAndHideBanner()
Stop audio playback and hide banner.
stopAudio()
Stop audio playback only (banner remains visible).
isPlaying()
Check if audio is currently playing.
Returns: Future<bool>
getCurrentPosition()
Get current audio position in seconds.
Returns: Future<double>
getDuration()
Get audio duration in seconds.
Returns: Future<double>
getProgress()
Get playback progress as a value between 0.0 and 1.0.
Returns: Future<double>
getCurrentVolume()
Get current system volume as a value between 0.0 and 1.0.
Returns: Future<double>
setVolume(double volume)
Set system volume.
Parameters:
volume(double): Volume level between 0.0 (mute) and 1.0 (maximum)
Banner Positions
The plugin supports the following banner positions:
'top-left': Top-left corner of the screen'top-right': Top-right corner of the screen'bottom-left': Bottom-left corner of the screen'bottom-right': Bottom-right corner of the screen (default)'center': Center of the screen'custom': Custom position using only offsetX and offsetY values
Features in Detail
Audio Playback
- Supports streaming audio from URLs
- Automatic audio session management
- Background playback support
- Error handling for network issues
Banner System
- Customizable size and position
- Progress ring visualization
- Smooth slide-in/slide-out animations
- Click-to-action functionality
- Image loading from URLs
Mute Detection
- Automatic volume monitoring
- Mute state detection
- Automatic mute notification banner display
- Configurable mute banner appearance
Volume Control
- System volume integration
- Real-time volume monitoring
- Cross-platform volume control
Platform-Specific Implementation
iOS (Objective-C)
- Uses
AVAudioPlayerfor audio playback MPVolumeViewfor volume controlUIViewanimations for banner transitions- Volume change notifications
- Safe area support
Android (Kotlin)
- Uses
MediaPlayerfor audio playback AudioManagerfor volume control- Custom
ProgressRingViewwith rectangular border progress visualization starting from 12 o'clock position - Clockwise progress animation synchronized with audio playback progress
- Glide for image loading
- Material Design animations
- PathMeasure-based progress drawing for smooth rectangular progress indication
- Detailed logging for progress tracking and debugging
Permissions
Android
The plugin requires the following permissions in your android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
iOS
No additional permissions required. The plugin uses standard audio playback APIs.
Example
See the example/ directory for a complete example application demonstrating all plugin features.
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Technical Notes
Architecture
The plugin follows Flutter's federated plugin architecture:
lib/plugin_test_platform_interface.dart: Platform interface definitionlib/plugin_test_method_channel.dart: Method channel implementationlib/plugin_test.dart: Public APIios/Classes/: iOS native implementationandroid/src/main/kotlin/: Android native implementation
Error Handling
The plugin includes comprehensive error handling for:
- Network connectivity issues
- Invalid audio URLs
- Permission errors
- Platform-specific audio system errors
Performance
- Efficient memory management for audio playback
- Optimized image loading and caching
- Smooth animations with proper cleanup
- Background processing for volume monitoring