rive-flutter icon indicating copy to clipboard operation
rive-flutter copied to clipboard

About Audio playback

Open Masataka-n opened this issue 1 year ago • 2 comments

Description

I'm trying to play audio with a simple one-shot animation.

In the iOS SDK, audio plays without specifying a stateMachine, but in the Flutter SDK, audio does not play unless a stateMachine is specified.

Is this intentional? Also, are there plans to fix this in future updates?

Sample code
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';

class RiveTestPage extends StatefulWidget {
  const RiveTestPage({super.key});

  @override
  State<RiveTestPage> createState() => _RiveTestPageState();
}

class _RiveTestPageState extends State<RiveTestPage> {
  RiveFile? _riveAudioAssetFile;

  @override
  void initState() {
    super.initState();
    _loadRiveFile();
  }

  Future<void> _loadRiveFile() async {
    final riveFile = await RiveFile.asset(
      'assets/anims/sound_kari.riv',
    );
    setState(() {
      _riveAudioAssetFile = riveFile;
    });
  }

  @override
  Widget build(BuildContext context) {
    if (_riveAudioAssetFile == null) {
      return const Center(child: CircularProgressIndicator());
    }
    return Scaffold(
      appBar: AppBar(
        title: const Text('Sample'),
      ),
      body: Center(
        child: RiveAnimation.direct(
          _riveAudioAssetFile!,
          //  ↓ If this is not specified, audio will not be played.
          // stateMachines: const ['State Machine 1'], 
          fit: BoxFit.cover,
        ),
      ),
    );
  }
}

Source .riv/.rev file

sample_resource.zip

Device & Versions (please complete the following information)

  • Device: [Android, iOS]
  • OS: [Android SDK API Level 34, iOS 17.5.1]
  • Flutter Version:
Flutter 3.22.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 761747bfc5 (3 months ago) • 2024-06-05 22:15:13 +0200
Engine • revision edd8546116
Tools • Dart 3.4.3 • DevTools 2.34.3

Masataka-n avatar Aug 26 '24 06:08 Masataka-n

Hi @Masataka-n the Flutter runtime does not report events outside of a state machine. We could look into adding this, but currently, there is a larger engineering effort to update the Rive Flutter runtime to use the same underlying Rive C++ runtime that iOS (and the other runtimes) uses. And this is our current focus for Flutter.

Once that change is done, then the behaviour should be the same. We're hard at work on that and in the upcoming weeks it'll be updated.

HayesGordon avatar Aug 27 '24 15:08 HayesGordon

Hi @HayesGordon Thank you for your response. I appreciate the hard work your team is putting into this. I’m looking forward to the upcoming updates.

Masataka-n avatar Aug 28 '24 02:08 Masataka-n