How to map or index to image and audio in flutter?

76 views
Skip to first unread message

Kumaresan Jackie

unread,
Apr 4, 2021, 2:06:41 AM4/4/21
to Flutter Development (flutter-dev)
  • How to map or index in image and audio in flutter

  • I am try to make Slider app If slider open play the audio

  • I was Stored 26 images and 26 audios

  • If first slide open play the first audio and 2nd image 2nd audio

  • I am using Swiper flutter_swiper: ^1.1.4 for sliding the slider was set to autoplay

  • I am using Audio player assets_audio_player: ^2.0.10

  • I am trying to make full offline App so That reason I am using assets_audio_player: ^2.0.10

import 'package:flutter/material.dart'; 
  import 'package:flutter_swiper/flutter_swiper.dart';
  import 'package:assets_audio_player/assets_audio_player.dart';
  // ignore: must_be_immutable 
  class Country extends StatelessWidget { 
 Country({Key key}) : super(key: key); 
  List images = [ 'images/Country/a.jpg', 'images/Country/b.jpg', 'images/Country/c.jpg', 'images/Country/d.jpg', 'images/Country/e.jpg', 'images/Country/f.jpg', 'images/Country/g.jpg', 'images/Country/h.jpg', 'images/Country/i.jpg', 'images/Country/j.jpg', 'images/Country/k.jpg', 'images/Country/l.jpg', 'images/Country/m.jpg', 'images/Country/n.jpg', 'images/Country/o.jpg', 'images/Country/p.jpg', 'images/Country/q.jpg', 'images/Country/r.jpg', 'images/Country/s.jpg', 'images/Country/t.jpg', 'images/Country/u.jpg', 'images/Country/v.jpg', 'images/Country/w.jpg', 'images/Country/x.jpg', 'images/Country/y.jpg', 'images/Country/z.jpg', ];
  List<T> map<T>( List list, Function handler, )
 List<T> result = [];
  for (var i = 0; 
i < list.length; 
i++
)
 {
 result.add(handler(i, list[i])); }
  return result;
 }
  @override 
 Widget build(BuildContext context) 
  return Scaffold(
 appBar: AppBar
( title: Text("Swipper"), ),
 body: Center( child: Container( height: 500.0, width: 370.0, 
 child: new Swiper( itemHeight: 400.0,
 itemBuilder: (BuildContext context, int index) 
  return new Image.asset( images[index],
 fit: BoxFit.fill, ); }, 
 autoplay: true, 
 itemCount: images.length, 
 autoplayDelay: 5000, 
 control: new SwiperControl(
color: Colors.redAccent)
, onIndexChanged: (index)
 { onPlayAudio(); }, )), ),
 bottomNavigationBar: BottomNavigationBar( 
 items: [ BottomNavigationBarItem( 
  // ignore: deprecated_member_use 
 title: Text("kumar"), icon: Icon(Icons.home), ), 
  }, ), ); } } 
  void onPlayAudio() async 
 AssetsAudioPlayer assetsAudioPlayer = AssetsAudioPlayer(); 
 assetsAudioPlayer.open( 
 Playlist(
 audios: 
 Audio("images/alpha/a.mp3"), Audio("images/alpha/b.mp3"), Audio("images/alpha/c.mp3"), Audio("images/alpha/d.mp3"), Audio("images/alpha/e.mp3"), Audio("images/alpha/f.mp3"), Audio("images/alpha/g.mp3"), Audio("images/alpha/h.mp3"), Audio("images/alpha/i.mp3"), Audio("images/alpha/j.mp3"), Audio("images/alpha/k.mp3"), Audio("images/alpha/l.mp3"), Audio("images/alpha/m.mp3"), Audio("images/alpha/n.mp3"), Audio("images/alpha/o.mp3"), Audio("images/alpha/p.mp3"), Audio("images/alpha/q.mp3"), Audio("images/alpha/r.mp3"), Audio("images/alpha/s.mp3"), Audio("images/alpha/t.mp3"), Audio("images/alpha/u.mp3"), Audio("images/alpha/v.mp3"), Audio("images/alpha/w.mp3"), Audio("images/alpha/x.mp3"), Audio("images/alpha/y.mp3"), Audio("images/alpha/z.mp3"), ], ),
 autoStart: true,
 playInBackground: PlayInBackground.disabledPause,
 loopMode: LoopMode.playlist //loop the full playlist );
 assetsAudioPlayer.next();
 assetsAudioPlayer.previous();
 assetsAudioPlayer.playlistPlayAtIndex(0); 
 assetsAudioPlayer.stop(); 
 assetsAudioPlayer.playOrPause();
 assetsAudioPlayer.play(); 
 assetsAudioPlayer.pause(); }

Suzuki Tomohiro

unread,
Apr 4, 2021, 10:43:03 AM4/4/21
to Kumaresan Jackie, Flutter Development (flutter-dev)
Where is the button to make the slide change?
How about playing the music when the slide chages?

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/e445b9f5-d053-47c7-a2b3-59bf9db14fe1n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages