-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem getting length of ogg/opus blob on edge #10
Comments
Hello @NeoCoderMatrix86, That's a very nice application ! I was able to import + play a opus file without any issues. See attached opus file which I used. |
@NeoCoderMatrix86 And if you are also interested in reading |
Thanks for the fast reply :). I'm currently investigating the bug and found some information: function setupAudioRecording() {
navigator.mediaDevices.getUserMedia({ audio: true }).then(stream => { handleAudioRecording(stream) }).catch(function (err) { handleAudioRecordingData = false; });
}
function handleAudioRecording(stream) {
rec = new MediaRecorder(stream);
rec.ondataavailable = e => {
audioChunks.push(e.data);
}
rec.onstop = () => {
let blob = new Blob(audioChunks, { 'type': 'audio/ogg; codecs=opus' });
var url = URL.createObjectURL(blob);
if (GLOBAL.ViewModeRecord !== null) {
GLOBAL.ViewModeRecord.invokeMethodAsync("AudioRecordingFinished", url);
}
}
}
function startAudioRecording() {
if (handleAudioRecordingData == true) {
audioChunks = [];
rec.start();
}
}
function stopAudioRecording() {
if (handleAudioRecordingData == true) {
rec.stop();
}
} ViewModeRecord: await JSRuntime.InvokeVoidAsync("startAudioRecording");
[JSInvokable()]
public void AudioRecordingFinished(String url)
{
//TODO: Customizable via options
Cuesheet.AudioFile = new AudioFile("Recording.ogg", url, "audio/ogg", true);
} AudioPlayer: private async Task OnPlayClicked()
{
if (soundId != null)
{
await Howl.Pause(soundId);
}
else
{
if ((Cuesheet == null) || (Cuesheet.AudioFile == null) || (Cuesheet.AudioFile.PlaybackPossible == false))
{
throw new ArgumentNullException(nameof(Cuesheet.AudioFile));
}
var options = new HowlOptions
{
Sources = new[] { Cuesheet.AudioFile.ObjectURL },
Formats = new[] { Cuesheet.AudioFile.AudioFileType.ToLower() },
Html5 = true
};
soundId = await Howl.Play(options);
}
} |
Sorry, I cannot really help you here. One thing which I noticed is that ".ogg" is normally using "Ogg / Vorbis" The demo file is an "Ogg - Opus" file. |
Is it possible to Debug into the exception, to get to know, what is causing the problem? I'm currently stuck here, because I'm not so deep into sound processing with howler framework. Maybe an update of howler could go good? |
Ok, I managed to debug the problem and this seems to be a Bug in your wrapper for me:
|
Did you try upgrading howler.js to a newer version? |
I updated howler.js to version 2.2.1, but that doesn't fix the problem. I'm still investigating the problem, seems to be a known bug of chrome/edge, that the stream has no duration. |
Can you attach your audio file which has this problem? Then I can investigate / debug this on my system. (And maybe searching / crossposting an issue to the howler.js github?) |
Well I think its not a problem of howler, since the playback starts even with the exception above. I think its more a conversion in .NET in this wrapper here, that makes the exception. I attached the file and renamed it for uploading. |
Playing this test file in my WASM example (play local OGG at https://stefh.github.io/Howler.Blazor) works fine on Edge. However, I did change the integer to double and passed the play-id to the 'duration' function, maybe that helps? Please test version 0.9.4 |
With the new Version 0.9.4 I get this exception:
I'm quite not shure, why it works in your samples but not in my code. Did you reencode the audio file? Because it has an duration of 5 seconds on your test site? Which version of .NET do you use? |
My example application is <PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
...
</PropertyGroup> And you use Maybe there's a difference? |
Ok, can you run a test on .NET 5.0? I can currently not switch to .netstandard since other libraries are not working than. |
I created the same example application with NET 5 |
I just checked, how you implemented your example and what I do in my application. To get the total time, you use the code
While I use an update timer:
So I think, in this case we have a problem of the function |
I just tried, getting TotalTime in the OnPlay Event. My application also crashes when I use the example code. I'm currently a bit stuck, it must have to do with the duration. |
The only thing what you can try is copy that "JsInteropHowl.js" file from this project into your project, use it in the html and change this code: getTotalTime: function () {
if (howl) {
const duration = howl.duration();
return Math.round(duration || 0);
}
return 0;
} to getTotalTime: function () {
if (howl) {
const duration = howl.duration();
if (duration === Infinity) {
return 0;
}
return Math.round(duration || 0);
}
return 0;
} and the same for onplay: async function (id) {
const duration = Math.round(howl.duration(id));
await dotnetReference.invokeMethodAsync('OnPlayCallback', id, duration);
}, |
Ok, good idea. I made the changes you suggested and debugged the javascript.
What happens inside OnPlayCallback? |
I don't know why the duration is Infinite in your case. onplay: async function (id) {
const duration = howl.duration(id);
if (duration === Infinity) {
await dotnetReference.invokeMethodAsync('OnPlayCallback', id, 0);
}
else {
await dotnetReference.invokeMethodAsync('OnPlayCallback', id, Math.round(duration));
}
}, This make sure to post |
Ok, this fixes the bug. You should include the javascript code in your release. The duration is infinite because it is a recording saved in a blob. Edge and Chrome doesn't automatically calculate the length and attach it, since Firefox does it. After one play of the recording, the length is calculated and the duration is no more infinite. |
In that case, I will also change the C# code. I'll change the duration from You can expect a new NuGet later today. |
I use your framework inside a blazor application (https://github.com/NeoCoderMatrix86/AudioCuesheetEditor) for editing cuesheets.
If I record some ogg/opus inside the application and play that record with your framework, I get an exception like this:
The text was updated successfully, but these errors were encountered: