A Flutter plugin for streaming Media on iOS and Android
Add Flutter Media Streamer to your project's dependencies:
dependencies:
flutter_media_streamer: ^1.0.2
On iOS add usage description for the Gallery inside your Runner/Info.plist
file:
<key>NSPhotoLibraryUsageDescription</key>
<string>This app shows photos from your photo library.</string>
On Android add READ_EXTERNAL_STORAGE
permission to Manifest:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
final res = await FlutterMediaStreamer.instance
.streamImageMetadata()
.take(100)
.toList();
The abstraction layer is used by streamImageMetadata
and produces objects
containing data common to both Android's MediaStore Columns and iOS PHAsset.
The entire query is wrapped as a Broadcast Stream so that no further actions are needed once you subscribe to the stream.
The stream can be manipulated as you wish (for example .take(X)
).
final res = await FlutterMediaStreamer.instance
.androidImagesMetadata(
limit: 10,
mediaColumns: [AndroidMediaColumn.duration, AndroidMediaColumn.title]
)
.toList();
The limit
argument controls the batch size in which data is transferred between the platform and the Dart code.
The baseColumns
, mediaColumns
, imageColumns
control which Android MediaStore information is delivered back through the stream.
final res = await FlutterMediaStreamer.instance
.iOSImagesMetadata()
.toList();
Will return a Stream with all available metadata exposed through iOS PHAsset API.
final res = await FlutterMediaStreamer.instance
.streamImageMetadata().toList();
for (var item in res) {
final Uint8List imageBytes = await FlutterMediaStreamer.instance
.getThumbnail(item.mediaQueryIdentifier);
// Do something with the data, such as display in Flutter Image.memory()
}
final res = await FlutterMediaStreamer.instance
.iOSImagesMetadata().toList();
for (var item in res) {
final Uint8List imageBytes = await FlutterMediaStreamer.instance
.getThumbnail(item.localIdentifier);
}
final res = await FlutterMediaStreamer.instance
.androidImagesMetadata().toList();
for (var item in res) {
final Uint8List imageBytes = await FlutterMediaStreamer.instance
.getThumbnail(item.contentUri);
}
final res = await FlutterMediaStreamer.instance
.streamImageMetadata().toList();
for (var item in res) {
final Uint8List imageBytes = await FlutterMediaStreamer.instance
.getImage(item.mediaQueryIdentifier);
}
final res = await FlutterMediaStreamer.instance
.streamImageMetadata().toList();
for (var item in res) {
final Uint8List imageBytes = await FlutterMediaStreamer.instance
.getImage(item.mediaQueryIdentifier, height: 400, width:640);
}
Use the height
and width
arguments to specify the desired size.
A value of -1 indicates the original size.
On iOS images will maintain aspect ratio and on Android they will be resized to the given dimentions. This will be fixed to allow customization in later version.