Krmad
Krmad
Aim: To develop a Flutter-based mobile application that enables users to interact with multimedia
features such as capturing photos, playing videos, playing audio, and sharing content seamlessly
across platforms.
Objective:
To build a Flutter application with a user-friendly interface for accessing multimedia
functionalities.
To allow users to capture photos using the device camera.
To enable users to play videos from a network URL.
Theory
Flutter is an open-source UI toolkit by Google used for building natively compiled applications
for mobile, web, and desktop from a single codebase. It supports rich multimedia features through
integration with device capabilities and third-party packages.
In this application:
The Image Picker plugin is used to capture images from the device’s camera.
The Video Player plugin allows video playback from a network source.
The Audio Players plugin supports audio streaming and playback.
The Flutter Share plugin provides the ability to share content through system-native share
dialogs.
Code
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:video_player/video_player.dart';
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter_share/flutter_share.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Multimedia & Sharing App',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomeScreen(),
);
}
}
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Multimedia & Sharing App'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => ImageCaptureScreen()),
);
},
child: Text('Capture Photo'),
),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => VideoPlayerScreen()),
);
},
child: Text('Play Video'),
),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => AudioPlayerScreen()),
);
},
child: Text('Play Audio'),
),
ElevatedButton(
onPressed: () {
_shareContent('Check out this amazing app!');
},
child: Text('Share Content'),
),
],
),
),
);
}
void _shareContent(String content) async {
await FlutterShare.share(
title: 'Share via',
text: content,
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Capture Photo'),
),
body: Center(
child: _image == null
? Text('No image selected.')
: Image.file(File(_image!.path)),
),
floatingActionButton: FloatingActionButton(
onPressed: _pickImage,
tooltip: 'Pick Image',
child: Icon(Icons.camera_alt),
),
);
}
}
@override
void initState() {
super.initState();
_controller = VideoPlayerController.network(
'https://www.videezy.com/water/13487-small-floating-stick-in-murky-water.mp4')
..initialize().then((_) {
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Play Video'),
),
body: Center(
child: _controller.value.isInitialized
? AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: VideoPlayer(_controller),
)
: CircularProgressIndicator(),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
if (_controller.value.isPlaying) {
_controller.pause();
} else {
_controller.play();
}
});
},
child: Icon(
_controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
),
),
);
}
@override
void dispose() {
super.dispose();
_controller.dispose();
}
}
class AudioPlayerScreen extends StatefulWidget {
@override
_AudioPlayerScreenState createState() => _AudioPlayerScreenState();
}
Output
Learning Outcome