0

What I have did so far, write a function to get the path of file

[JSInvokable]
public async static Task<string> GetPath()
{
    return FileSystem.AppDataDirectory+ "/contents/interactive_video";
}

in my js file called this

async function play() {
try {
    const { H5P } = H5PStandalone || {};

    DotNet.invokeMethodAsync('BlazorApp', 'GetPath')
        .then(async path => {
            console.log(path);
            await new H5P(document.getElementById('h5p-container'), { h5pJsonPath: path, frameJs: 'h5p/assets/frame.bundle.js', frameCss: 'h5p/assets/styles/h5p.css' })
                .then(function () {
                    // this is where you will listen for the xAPI event
                    H5P.externalDispatcher.on('xAPI', (event) => {
                        // add your logic to send the event to the LRS  here.             
                        console.log('xAPI event: ', event); //(I am just logging to browser developer console for demo purpose)
                    });
                });
        });
} catch (e) {
    console.log('error : ', e);
}

}

now, when I run the application it throws 404 error on this address

https://0.0.0.0/data/user/0/com.companyname.blazorapp/files/contents/interactive_video/h5p.json
XTOO
  • 33
  • 6
  • Those days, it is full scope adventure to read a file from external storage, even using native. You use not just MAUI, but Blazor Maui, and on top of it you want to do it in JS. – H.A.H. Jun 06 '23 at 14:05
  • Is this targetting WIndows, or a mobile emulator? To be sure permissions are correctly set, do a simple test in c# with that AppDataDirectory path. If that doesn't work, then there is a problem with permissions. ( Razor c# code is running in the app; it has whatever permissions the app has.) If it does work, then there is something different about accessing from JS. In that case, consider writing the file access code in c#. – ToolmakerSteve Jun 06 '23 at 19:40
  • I'm targetting android device, I have used below code to read a file from c# and its working fine 'code' var docsDirectory = Android.App.Application.Context.GetExternalFilesDir(Android.OS.Environment.DirectoryDownloads).AbsoluteFile"; but when I try to convert this into string and pass it into js function 404 error happened – XTOO Jun 07 '23 at 08:15
  • any help would be appritiated. Thanks – XTOO Jun 07 '23 at 08:18
  • can't i just download the file in wwwroot folder? – XTOO Jun 09 '23 at 04:21

0 Answers0