Skip to content

[Blazor] Cannot read/write properties on JSObjectReference #26107

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

Closed
mrpmorris opened this issue Sep 20, 2020 · 1 comment
Closed

[Blazor] Cannot read/write properties on JSObjectReference #26107

mrpmorris opened this issue Sep 20, 2020 · 1 comment
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@mrpmorris
Copy link

mrpmorris commented Sep 20, 2020

Given the following JavaScript

export function createAudio(src) {
	return new Audio(src);
}

I can load it in, create an Audio instance, and start it playing like this

@page "/"
@inject IJSRuntime JSRuntime;

<button @onclick=@Play>Play</button>

	JSObjectReference AudioLib;
	JSObjectReference Audio;

	protected override async Task OnInitializedAsync()
	{
		await base.OnInitializedAsync();
		AudioLib = await JSRuntime.InvokeAsync<JSObjectReference>("import", "/Audio.js");
		Audio = await AudioLib.InvokeAsync<JSObjectReference>("createAudio", "/ElementsSong.ogg");
	}

	protected void Play()
	{
		_ = Audio.InvokeVoidAsync("play");
	}

However, I cannot get the currentTime of the Audio like this

CurrentTime = await Audio.InvokeAsync<decimal>("currentTime");

Instead I have to do something like this to convert the p

export function createAudio(src) {
	let result = new Audio(src);
	result.getCurrentTime = () => result.currentTime;
	return result;
}
@pranavkm pranavkm added the area-blazor Includes: Blazor, Razor Components label Sep 20, 2020
@pranavkm
Copy link
Contributor

Dup of #25756.

@ghost ghost locked as resolved and limited conversation to collaborators Oct 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

No branches or pull requests

2 participants