颤抖不播放音频

时间:2020-06-28 12:23:51

标签: android flutter dart

///忽略此行,因为您是程序员// 我是新手,我做了这个木琴应用程序,一切都很好,没有任何错误。但是声音不能在模拟器中播放,你们可以在这里解决问题吗?

pubspec.yaml也很好。那里没问题。

颤振: Uses-material-design:true

资产: -资产/

import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';

void main() {
 runApp(MaterialApp(
   debugShowCheckedModeBanner: false,
   home: XyloPhone(),
 ));
}

class XyloPhone extends StatefulWidget {
 @override
 _XyloPhoneState createState() => _XyloPhoneState();
}

class _XyloPhoneState extends State<XyloPhone> {
 final _controller1 = VideoPlayerController.asset('assets/1.mp3');
 final _controller2 = VideoPlayerController.asset('assets/2.mp3');
 final _controller3 = VideoPlayerController.asset('assets/3.mp3');
 final _controller4 = VideoPlayerController.asset('assets/4.mp3');
 final _controller5 = VideoPlayerController.asset('assets/5.mp3');
 final _controller6 = VideoPlayerController.asset('assets/6.mp3');
 final _controller7 = VideoPlayerController.asset('assets/7.mp3');

 @override
 Widget build(BuildContext context) {
   return Scaffold(
     backgroundColor: Colors.grey[800],
     body: SafeArea(
       child: Padding(
         padding: const EdgeInsets.all(20.0),
         child: Column(
           crossAxisAlignment: CrossAxisAlignment.center,
           mainAxisAlignment: MainAxisAlignment.center,
           children: <Widget>[
             //First One
             SizedBox(
               height: 60.0,
               width: 30.0,
               child: Container(
                 decoration: BoxDecoration(
                   color: Colors.white,
                   borderRadius: BorderRadius.only(
                       topRight: Radius.circular(10),
                       topLeft: Radius.circular(10)),
                 ),
               ),
             ),
             InkWell(
               onTap: () {
                 _controller1.play();
               },
               child: Container(
                 height: 50,
                 width: 230,
                 decoration: BoxDecoration(
                   color: Colors.green[700],
                   borderRadius: BorderRadius.circular(20),
                 ),
               ),
             ),
             SizedBox(
               height: 30.0,
               width: 30.0,
               child: Container(color: Colors.white),
             ),
             //Second One
             InkWell(
               onTap: () {
                 _controller2.play();
               },
               child: Container(
                 height: 50,
                 width: 250,
                 decoration: BoxDecoration(
                   color: Colors.blue[800],
                   borderRadius: BorderRadius.circular(20),
                 ),
               ),
             ),
             SizedBox(
               height: 30.0,
               width: 30.0,
               child: Container(color: Colors.white),
             ),
             //third one
             InkWell(
               onTap: () {
                 _controller3.play();
               },
               child: Container(
                 height: 50,
                 width: 270,
                 decoration: BoxDecoration(
                   color: Colors.amber,
                   borderRadius: BorderRadius.circular(20),
                 ),
               ),
             ),
             SizedBox(
               height: 30.0,
               width: 30.0,
               child: Container(color: Colors.white),
             ),
             //forth one
             InkWell(
               onTap: () {
                 _controller4.play();
               },
               child: Container(
                 height: 50,
                 width: 290,
                 decoration: BoxDecoration(
                   color: Colors.orange[800],
                   borderRadius: BorderRadius.circular(20),
                 ),
               ),
             ),
             SizedBox(
               height: 30.0,
               width: 30.0,
               child: Container(color: Colors.white),
             ),
             //fifth one
             InkWell(
               onTap: () {
                 _controller5.play();
               },
               child: Container(
                 height: 50,
                 width: 310,
                 decoration: BoxDecoration(
                   color: Colors.purple,
                   borderRadius: BorderRadius.circular(20),
                 ),
               ),
             ),
             SizedBox(
               height: 30.0,
               width: 30.0,
               child: Container(color: Colors.white),
             ),
             //sixth 0ne
             InkWell(
               onTap: () {
                 _controller6.play();
               },
               child: Container(
                 height: 50,
                 width: 330,
                 decoration: BoxDecoration(
                   color: Colors.red[700],
                   borderRadius: BorderRadius.circular(20),
                 ),
               ),
             ),
             SizedBox(
               height: 30.0,
               width: 30.0,
               child: Container(color: Colors.white),
             ),
             //seventh one
             InkWell(
               onTap: () {
                 _controller7.play();
               },
               child: Container(
                 height: 50,
                 width: 400,
                 decoration: BoxDecoration(
                   color: Colors.teal,
                   borderRadius: BorderRadius.circular(20),
                 ),
               ),
             ),
             SizedBox(
               height: 60.0,
               width: 30.0,
               child: Container(
                 decoration: BoxDecoration(
                   color: Colors.white,
                   borderRadius: BorderRadius.only(
                       bottomRight: Radius.circular(10),
                       bottomLeft: Radius.circular(10)),
                 ),
               ),
             ),
           ],
         ),
       ),
     ),
   );
 }
}

1 个答案:

答案 0 :(得分:0)

_controller.setVolume(1.0); 添加到您的控制器。