0% found this document useful (0 votes)
9 views5 pages

Krmad

The document outlines the development of a Flutter-based mobile application that allows users to capture photos, play videos, and stream audio while sharing content across platforms. It details the use of various plugins for multimedia functionalities and provides code snippets for the app's structure, including screens for image capture, video playback, and audio playback. The aim is to create a user-friendly interface that integrates these features seamlessly.

Uploaded by

f4g3gfza2x
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

Krmad

The document outlines the development of a Flutter-based mobile application that allows users to capture photos, play videos, and stream audio while sharing content across platforms. It details the use of various plugins for multimedia functionalities and provides code snippets for the app's structure, including screens for image capture, video playback, and audio playback. The aim is to create a user-friendly interface that integrates these features seamlessly.

Uploaded by

f4g3gfza2x
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Experiment 10

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,
);
}
}

class ImageCaptureScreen extends StatefulWidget {


@override
_ImageCaptureScreenState createState() => _ImageCaptureScreenState();
}
class _ImageCaptureScreenState extends State<ImageCaptureScreen> {
final ImagePicker _picker = ImagePicker();
XFile? _image;

Future<void> _pickImage() async {


final pickedFile = await _picker.pickImage(source: ImageSource.camera);
setState(() {
_image = pickedFile;
});
}

@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),
),
);
}
}

class VideoPlayerScreen extends StatefulWidget {


@override
_VideoPlayerScreenState createState() => _VideoPlayerScreenState();
}
class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
late VideoPlayerController _controller;

@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();
}

class _AudioPlayerScreenState extends State<AudioPlayerScreen> {


final AudioPlayer _audioPlayer = AudioPlayer();
bool _isPlaying = false;

void _togglePlay() async {


if (_isPlaying) {
await _audioPlayer.pause();
} else {
await _audioPlayer.play(
'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3');
}
setState(() {
_isPlaying = !_isPlaying;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Play Audio'),
),
body: Center(
child: IconButton(
icon: Icon(_isPlaying ? Icons.pause : Icons.play_arrow),
onPressed: _togglePlay,
),
),
);
}
}

Output

Learning Outcome

You might also like