Today, I make application to play music on Android.
I have failed when using MediaPlayer to play an audio file; it can't play any file audio.
ON debug console:
I/flutter ( 5455): taped
E/MediaPlayerNative( 5455): error (1, -2147483648)
E/MediaPlayer( 5455): Error (1,-2147483648)
E/MediaPlayerNative( 5455): pause called in state 0, mPlayer(0xc83ffa40)
E/MediaPlayerNative( 5455): error (-38, 0)
E/MediaPlayerNative( 5455): Attempt to perform seekTo in wrong state: mPlayer=0xc83ffa40, mCurrentState=0
E/MediaPlayerNative( 5455): error (-38, 0)
2
E/MediaPlayer( 5455): Error (-38,0)
This is my code:
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
FlatButton.icon(
label: Text('ss'),
icon: Icon(Icons.ac_unit_outlined),
onPressed: () {
print('taped');
final player = AudioCache();
player.play('yagami.wav');
},
),
],
),
);
}
On pubspec.yaml:
dependencies:
audioplayers: 0.17.0
I've tried an older version of packages, but it didn't work out.
How to solve this problem?
or any other packages to play audio on assets?
Something that might help is creating your player just once at the beginning, and not everytime you press the button as that defeats the purpose of AudioCache.
So remove final player = AudioCache(); from the OnPressed function.
Related
I have this question. My code actually working but when I click my button there is no new sound. I actually change the name of directory folder but it didn't work.
import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
import 'dart:math';
void main() => runApp(XylophoneApp());
class XylophoneApp extends StatelessWidget {
void playSound () {
final player = AudioPlayer();
int soundNumber = Random().nextInt(5) + 1;
player.setSource(AssetSource('sounds/note$soundNumber.wav'));
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Center(
child:TextButton
(onPressed: () {
playSound();
},
child:const Text('Click Me')),
),
),
),
);
}
}
Here is the result:
E/flutter ( 8119): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)]
Unhandled Exception: Unable to load asset: assets/audios/note1.wav
E/flutter ( 8119): #0 PlatformAssetBundle.load
(package:flutter/src/services/asset_bundle.dart:237:7)
E/flutter ( 8119): <asynchronous suspension>
yaml file :
assets:
- assets/sounds/
You have to add this file in assets section in pubspec.yaml file
assets:
- assets/audios/note1.wav
try to move your sub audio folder out of your former asset folder that comes by default . and place it direct to your project new folder like lib folder in the first level
sometimes flutter does not see the external files .
and for better work done clean your engine .
As I'm working in the Xylophone project
I did this to run my APP:
You can add new project and then rewrite your code line by line and debug it
probably it is because of some change that you have done.
Change the package I recommend you to add the new package in new projects
PS: If you are in windows before everything quit the Android Studio from the Task Manager and shut down your computer then start everything from the beginning
If you find new solution let me know
Thank you
Hey I am using ShowCaseView in my Flutterapp. When I first open my app, after registration there is no showcase, not even the icon which should be 'showcased' is shown. But when I am closing the app and opening it again it works just fine.
Thats the code referring to showcase:
class _HomeSearchPageState extends State<HomeSearchPage> {
final keyOne = GlobalKey();
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback(
(_) => ShowCaseWidget.of(context).startShowCase([
keyOne,
]),
);
}
And now the scaffold:
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(getTopBarSize()),
child: AppBar(
automaticallyImplyLeading: false,
title: Text(
'username',
style: TextStyle(fontSize: 14),
),
actions: <Widget>[
Showcase(
key: keyOne,
description: 'test',
child: IconButton(
icon: Icon(Icons.search),
onPressed: () {
showSearch(context: context, delegate: DataSearch())
.whenComplete(() => setName());
}),
),
],
),
),)
I did exactly the same as in the Github example but still it throws this error the first time:
════════ Exception caught by widgets library ═══════════════════════════════════
The following NoSuchMethodError was thrown building IconTheme(color: Color(0xffffffff)):
The getter 'activeWidgetIds' was called on null.
Receiver: null
Tried calling: activeWidgetIds
The relevant error-causing widget was
AppBar
lib\Views\HomeSearchPage.dart:182
When the exception was thrown, this was the stack
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 ShowCaseWidget.activeTargetWidget
package:showcaseview/showcase_widget.dart:51
#2 _ShowcaseState.showOverlay
package:showcaseview/showcase.dart:171
#3 _ShowcaseState.didChangeDependencies
package:showcaseview/showcase.dart:164
#4 StatefulElement._firstBuild
package:flutter/…/widgets/framework.dart:4786
════════ Exception caught by rendering library ═════════════════════════════════
Each child must be laid out exactly once.
The relevant error-causing widget was
AppBar
lib\Views\HomeSearchPage.dart:182
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by scheduler library ═════════════════════════════════
Exception: Please provide ShowCaseView context
════════ Exception caught by widgets library ═══════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 6224 pos 12: '_children.contains(child)': is not true.
The relevant error-causing widget was
AppBar
lib\Views\HomeSearchPage.dart:182
════════════════════════════════════════════════════════════════════════════════
These errors are kind a looped, so the debug console shows them all the time.
The only difference between the first app opening and the second one is: In the first one the user enters a registrationpage and after this he enters the page with the showcaseview. In the second the user enters directly the page with the showcaseview. How can this affect the showcase and more accurate why does this throw the errors?
Not sure if we share a similar issue but maybe my answer will help you somehow :). The issue occurs when I navigate to the page where I have Showcase widget, but it does not occur when I navigate "back" to the page from the other page.
Maybe you can check this page "This error is thrown if you haven't wrapped your widget with ShowCaseWidget. This is not the problem with the package itself."
Thus, I tried raising the level of the ShowCaseWidget in the main.dart and the issue was solved.
void main() {
// runApp(MyApp());
runApp(
ShowCaseWidget(
autoPlay: false,
autoPlayDelay: Duration(seconds: 8),
autoPlayLockEnable: false,
builder: Builder(
builder: (context) => MyApp(),
),
onStart: (index, key) {
print('onStart: $index, $key');
},
onComplete: (index, key) {
print('onComplete: $index, $key');
},
),
);
}
So far the app still works well. I will report again here in case any issues occur.
I have implemented Google Authentication with FlutterFire. I use the official package to sing in users.
However, if I navigate to a page where the user profile picture is seen and try to render the GoogleUserCircleAvatarar, although the page seems to be working just fine, I get an error in the console:
════════ Exception caught by image resource service ════════════════════════════════════════════════
Exception: Invalid image data
════════════════════════════════════════════════════════════════════════════════════════════════════
On the screen, it takes a few milliseconds, to load up the picture. Before it's loaded, I can see the placeholder image (First letter of the users initials on a filled background) next to the user's name and email address (so the currentUser is loaded) which transitions to the user profile picture. As I am using the recommended Widget, I am confused how should I prevent the error from happening.
Code:
if (widget.userService.currentUser != null) {
return Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
ListTile(
leading: GoogleUserCircleAvatar(
identity: widget.userService.currentUser,
),
title: Text(widget.userService.currentUser.displayName ?? ''),
subtitle: Text(widget.userService.currentUser.email ?? ''),
),
const Text("Signed in successfully."),
RaisedButton(
child: const Text('SIGN OUT'),
onPressed: _handleSignOut,
),
],
);
} else {
...
currentUser object is created with the official API:
currentUser = await GoogleSignIn().signIn();
and my pubspec.yml:
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^0.14.0+1
provider: ^4.3.2+2
google_sign_in: "^4.5.1"
firebase_core: "^0.5.0+1"
firebase_auth: "^0.18.1+2"
This issue should've resolved on the latest version of the google_sign_in plugin. More details of the fix for the issue is discussed on this pull request.
I'm having this problem about flutter and firebase(realtime-database).
Unhandled Exception: MissingPluginException(No implementation found for method Query#observe on channel plugins.flutter.io/firebase_database)
Here is the error in terminal
error
// error message
[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method Query#observe on channel plugins.flutter.io/firebase_database)
#0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:154:7)
<asynchronous suspension>
#1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
#2 Query._observe.<anonymous closure> (package:firebase_database/src/query.dart:50:38)
#3 _runGuarded (dart:async/stream_controller.dart:820:24)
#4 _BroadcastStreamController._subscribe (dart:async/broadcast_stream_controller.dart:215:7)
#5 _ControllerStream._createSubscription (dart:async/stream_controller.dart:833:19)
#6 _StreamImpl.listen (dart:async/stream_impl.dart:475:9)
#7 Stream.first (dart:async/stream.dart:1254:25)
#8 Query.once (package:firebase_database/src/query.dart:84:55)
#9 _IoTState.initState (package:flutter_try_iot/main.dart:36:13)
#10 StatefulElement._f<…>
I'm trying to get data from firebase to display in flutter app.
Here is my code main.dart
class _IoTState extends State<IoT> {
final getIot = FirebaseDatabase.instance.reference();
final getData = FirebaseDatabase.instance.reference().child('xxx-xxx');
String temperatue = "0";
String illuminance = "0";
List<String> temp = [];
List<String> light = [];
#override
void initState(){
getData.once().then((DataSnapshot snapshot){
if (snapshot.value == null) {
print("Item doesn't exist in the db");
} else {
print("Item exists in the db");
}
});
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Color(0xFF7ACADA),
title: Text(
"IoT ZigBee Simulation",
textAlign: TextAlign.center,
style: TextStyle(
color: Color(0xFF1A1244)
),
),
),
body: Column(
),
);
}
}
pubspec.yaml
firebase_core: ^0.4.5
firebase_database: ^3.1.6
flutter_icons: ^1.1.0
fl_chart: ^0.10.1
I follow instructions to add ios to firebase .ios add firebase
no issues found by flutter doctor
I follow other peoples suggestion to do flutter clean & flutter packages get, but still not able to fix this problem
https://github.com/flutter/flutter/issues/13971
terminal
Also pop up a window telling me The file “Runner.xcworkspace” has been modified by another application" everytime I execute flutter clean/ flutter packages get
I successfully connect to firebase yesterday, but after I close my simulator I start to receive error message
success picture
Please give me some solution or advice to fix this problem, thanks.
Please tell me if I need to provide additional information
I am launching a flutter app (App 1) from another flutter app (App 2) on Android and it works perfectly. However, I keep getting the same error on IOS. It does not recognize the package name.
I have tried with multiple apps but is the same result, it currently just recognizes the calendar package.
pubspec.yaml file flutter_appavailability
main.dart App 2
import 'package:flutter_appavailability/flutter_appavailability.dart';
//Future void method
if (Platform.isIOS) {
_installedApps = [
{"app_name": "example", "package_name": "com.flutter.example"},
];
print(await AppAvailability.checkAvailability("com.flutter.example")); //ERROR
//Widget build
return Container {
child : Row(
...
GestureDetector(
...
onTap: () {
Scaffold.of(context).hideCurrentSnackBar();
AppAvailability.launchApp(installedApps[0].["package_name"])
.then((_) {
print("App ${installedApps[0]["app_name"]} launched!");
}).catchError((err) {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(
"App ${installedApps[0]["app_name"]} not found!")));
print(err);
});
...
),
}
info.plist App 1
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
project.pbxproj App 1
PRODUCT_BUNDLE_IDENTIFIER = com.flutter.example;
Output App 2
[VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: PlatformException(, App not found com.flutter.example, null)
#0 AppAvailability.checkAvailability (package:flutter_appavailability/flutter_appavailability.dart:40:9)