Closed ptrbrynt closed 2 months ago
This issue is stale because it has been open 90 days with no activity. Leave a comment or this will be closed in 7 days.
Did this end up getting implemented?
This would be so helpful
This issue is stale because it has been open 90 days with no activity. Leave a comment or this will be closed in 7 days.
/remove lifecycle stale
Can we reopen this? Still keen to have this functionality Thanks!
ya would be great to have panning
Yes. Sure. This is definitely something that is easy to implement and that is badly missing. Actually, I am busy working on Flutter Sound V10.0. I can't implement new features in the 9.x, if I really want to release one day 10.0. So I only do maintenance on the 9.x (fix bugs).
When 10.0 will be released, we will see what we will want to do on 9.x. If someone can do a PR on 9.x, it would be wonderful.
I added this request in the Kanban table
If there's ever this feature would it be possible to control the left and right volume of the audio and broadcast to both left and right channel?
@changcw83 : thank you so much for your proposition to contribute to Flutter Sound project. Flutter Sound 9.x has a complicated architecture for legacy reasons. Flutter Sound 10.0 will have a much simpler architecture and it will be easier to contribute to it.
I think that the first step for you is to have a working dev. You can have a look to the dev documentation but this page is very outdated.
I suggest that you do :
git clone --recursive git@github.com:Canardoux/flutter_sound.git
cd flutter_sound
bin/reldev.sh DEV
and then try to execute the example under Android Studio
or Visual Studio Code
(I use Android Studio).
btw :
gsed
to execute bin/reldev.sh DEV
Having a running dev environment is probably the the most painful step, but this is a required step. When you will have a dev environment working, it will be simpler. I will help you.
Got the example to run, ready to develop the new feature, do guide me how, thanks
Yeah! π You did the most difficult step. Now Everything will be easy : Here are the layers :
You can operate on those 4 layers in the order that you prefer. Top Down, or Bottom up. (or on the 4 layers at the same time!)
1 - The examples You want to create a new example. The example is a driver which calls all the elementary examples. You will add in this dart file an import to your example. Then you will create your example as a new dir inside https://github.com/Canardoux/flutter_sound/tree/master/flutter_sound/example/lib. You probably want to copy a very simple example witch has already a cursor, like Volume Control
2- The dart code
You probably want to add a new verb setPanner()
or something like that. This verb will call a new procedure inside flutter_sound_platform_interface/flutter_sound_player_platform_interface.dart
and flutter_sound_platform_interface/method_channel_flutter_Sound_recorder.dart
3- The native code I suggest that you don't work at the same time on the three platforms (Android, iOS and Web). Let us say that you choose iOS. There are many files inside flutter_sound/flutter_sound/ios/Classes but they are just a bridge to FlutterSoundCore. You will modify FlutterSoundPlayerManager.mm and FlutterSoundPlayer.mm. You will just call a new verb inside FlutterSoundCore
4- flutter_sound_core You will add your new verb inside flutter_sound_core/ios//Classes/FlautoPlayer.mm
It should not be too much difficult. Probably you can duplicate the setVolume
code on the 4 layers and modify it for your new thing.
Of course, don't hesitate to ask me if any question.. I will be very glad to help you.
The dart implementation of setSpeed()
is in :
I will likely just overload the setvolume to handle two parameters left and right.
Think I sort of figured out android's implementation, but for ios, think I'm stuck seems not so direct to set left and right volume
There are 3 platforms : iOS, Android and Web. Don't forget Web.
Ok, but can you give some suggestions on ios? Seems lacking the functionality to set left and right volume
I don't have any idea of what it can be achieved on iOS. The only thing I am sure, is that it will be simple to do, because setting the balance on a mediaPlayer is a basic feature.
Got the following from chatgpt, shall try it
To pan volume in iOS, you can use the AVAudioEngine
class along with AVAudioPlayerNode
and AVAudioEnvironmentNode
. Here's a basic example to demonstrate how to implement panning in your iOS app using Swift:
import AVFoundation
let audioEngine = AVAudioEngine()
let playerNode = AVAudioPlayerNode()
let environmentNode = AVAudioEnvironmentNode()
audioEngine.attach(playerNode)
audioEngine.attach(environmentNode)
audioEngine.connect(playerNode, to: environmentNode, format: nil)
audioEngine.connect(environmentNode, to: audioEngine.mainMixerNode, format: nil)
do {
try audioEngine.start()
} catch {
print("Audio Engine couldn't start: \(error.localizedDescription)")
}
if let fileURL = Bundle.main.url(forResource: "your_audio_file", withExtension: "mp3") {
do {
let audioFile = try AVAudioFile(forReading: fileURL)
playerNode.scheduleFile(audioFile, at: nil, completionHandler: nil)
} catch {
print("Couldn't load the audio file: \(error.localizedDescription)")
}
}
You can control the panning by setting the position of the AVAudio3DPoint
object.
x
coordinate controls the left/right panning.y
coordinate controls the up/down panning.z
coordinate controls the front/back distance.let panPosition = AVAudio3DPoint(x: 1.0, y: 0.0, z: 0.0)
environmentNode.listenerPosition = panPosition
playerNode.play()
AVAudioPlayerNode
is used to play the audio.AVAudioEnvironmentNode
is responsible for controlling the spatial effects, such as panning.x
value in AVAudio3DPoint
, you can control the left/right panning effect.x
coordinate value ranges from -1.0
(full left) to 1.0
(full right), with 0.0
being the center.This approach gives you a flexible way to pan audio in your iOS application.
Another attempt in objective-c seems easier
To pan audio in iOS using Objective-C, you can use the AVAudioPlayer
class, which provides control over audio playback, including panning. Here's how you can achieve panning:
Import the necessary framework:
#import <AVFoundation/AVFoundation.h>
Set up your audio player:
Load your audio file into an AVAudioPlayer
instance.
NSString *path = [[NSBundle mainBundle] pathForResource:@"your-audio-file" ofType:@"mp3"];
NSURL *soundURL = [NSURL fileURLWithPath:path];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:nil];
Set the pan property:
The pan
property of AVAudioPlayer
controls the stereo pan position of the audio. The range is from -1.0 (full left) to 1.0 (full right), with 0.0 being the center.
audioPlayer.pan = -1.0; // Full left
// or
audioPlayer.pan = 1.0; // Full right
// or
audioPlayer.pan = 0.0; // Center (default)
Play the audio:
Finally, start playing the audio.
[audioPlayer play];
This will allow you to control the panning of your audio in your iOS application. If you need more advanced audio handling, you might also consider using the AVAudioEngine
framework, which provides more granular control over audio processing.
The AVAuidioPlayer in iOS is in flutter_sound_core/ios/Classes/FlautoPlayerEngine
You will have to add a virtual function in the interface and do something for the other classes implementing this virtual function.
The other classes are mainly to support PlayFromStream
.
In a first step, you can do an exception Not implemented for Streams
.
Now I need to host an audio with separate left and right channels to put in example
I guess that all the examples under https://tau.canardoux.xyz/danku/extract/ (for example https://tau.canardoux.xyz/danku/extract/05.mp3) are stereo. If you want to put a new example on this host, just give it to me
Ok, no problem easier to use existing ones, I try to get the example to work.
On Sun, 18 Aug 2024 at 20:24, Larpoux @.***> wrote:
I guess that all the examples under https://tau.canardoux.xyz/danku/extract/ (for example https://tau.canardoux.xyz/danku/extract/05.mp3) are stereo. If you want to put a new example on this host, just give it to me
β Reply to this email directly, view it on GitHub https://github.com/Canardoux/flutter_sound/issues/77#issuecomment-2295243353, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA6OPL2D5ER5473REWTRKTDZSCG7NAVCNFSM4HI222J2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMRZGUZDIMZTGUZQ . You are receiving this because you were mentioned.Message ID: @.***>
Think this clip should be a clearer example
https://tau.canardoux.xyz/danku/extract/leftright.mp3 is now on Canardoux host
What do I have to do? I added setVolumePan based on setVolume, finding all occurrences and mimicing it
E/flutter (10299): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method setVolumePan on channel xyz.canardoux.flutter_sound_player)
E/flutter (10299): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:332)
E/flutter (10299):
When you will be ready, you may do a Pull Request. Did you fork the repo ?
have done so, first time in my life :)
You probably modified also flutter_sound_core. Donβt forget to do another pull request for this repo
ok done too for flutter_sound_core and flutter_sound_web
This is great. Congratulations π₯ . I am going to look your pull request. If/when everything will seem good I will merge your pr in the master branch. Then I will do some very quick tests and I will release a new flutter sound version.
there is also the problem of the documentation: actually it is in bad shape. Some new features are not included in the 9.x documentation. I am busy working on a new documentation for 10.0 . You can choose to include your new feature in the 9.x documentation, or wait the 10.0 . I vote for the former: 9.x will be maintained during a foreseeable future. Probably during one or two years.
fixed some errors, trusted chatgpt too much.
On Sun, 18 Aug 2024 at 22:25, Larpoux @.***> wrote:
This is great. Congratulations π₯ . I am going to look your pull request. If/when everything will seem good I will merge your pr in the master branch. Then I will do some very quick tests and I will release a new flutter sound version.
there is also the problem of the documentation: actually it is in bad shape. Some new features are not included in the 9.x documentation. I am busy working on a new documentation for 10.0 . You can choose to include your new feature in the 9.x documentation, or wait the 10.0 . I vote for the former: 9.x will be maintained during a foreseeable future. Probably during one or two years.
β Reply to this email directly, view it on GitHub https://github.com/Canardoux/flutter_sound/issues/77#issuecomment-2295281853, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA6OPLYW6XHJP3367FV6FB3ZSCVERAVCNFSM4HI222J2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMRZGUZDQMJYGUZQ . You are receiving this because you were mentioned.Message ID: @.***>
Apologise for the buggy version, figured out the fix myself, tested on ios simulator and my android phone
Apologise for the buggy version, figured out the fix myself, tested on ios simulator and my android phone
No problem, Chang. I appreciate this work that you do on Flutter Sound to let it be better. Actually you are the only developer on Flutter Sound, except me. Congratulations. We really need people to work on free projects. I am very grateful for your contribution.
Flutter Sound 9.11.2 is released.
setVolumePan
. (#77). Many thanks to Chang Cheng Wei for his contribution.
I'd love to have a way to control the left/right balance of the currently playing audio. It looks like the iOS and Android audio player APIs both support this so I guess it's possible with Flutter!