audio player implentation with FuseJS

I’ve reinstalled last version of fusetools, cleaned as stated in the instructions and build

fuse --version
# -> Fuse version 0.12.3 (build 6348)
uno clean
fuse build --target=Android --run -v
</code></pre></div>
<p>and I get the following error:</p>
<div class="highlighted_code"><pre><code class="language-sh">
Installing APK on 1 device(s)
Launching actitity &#39;mp3&#39;
05-02 16:41:17.830  8299  9791 I ActivityManager: Start proc 25916:com.mp3/u0a229 for activity com.mp3/.mp3
05-02 16:41:17.870 25916 25916 I art     : Late-enabling -Xcheck:jni
05-02 16:41:18.051 25916 25916 I LoadedApk: No resource references to update in package common
05-02 16:41:18.052 25916 25916 I LoadedApk: No resource references to update in package com.wsdeveloper.galaxys7
05-02 16:41:18.052 25916 25916 I LoadedApk: No resource references to update in package com.wsdeveloper.galaxys7
05-02 16:41:18.357 25916 25916 D mp3     : SUT: false  CML: false  SDK: 23
05-02 16:41:18.661 25916 25916 I Adreno-EGL: &lt;qeglDrvAPI_eglInitialize:379&gt;: QUALCOMM Build: 09/02/15, 76f806e, Ibddc658e36
05-02 16:41:19.000 25916 25986 D OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
05-02 16:41:19.106 25916 25986 I OpenGLRenderer: Initialized EGL, version 1.4
05-02 16:41:19.881 25916 25987 E MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0
05-02 16:41:19.881 25916 25987 E MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0
05-02 16:41:19.917 25916 25916 I mp3     : Unhandled exception: 
05-02 16:41:19.917 25916 25916 I mp3     : 

05-02 16:41:19.917 25916 25916 I mp3     : Name: Object reference was null

05-02 16:41:19.917 25916 25916 I mp3     : Error message: Uncaught Object reference was null

05-02 16:41:19.917 25916 25916 I mp3     : File name: MainView.ux

05-02 16:41:19.917 25916 25916 I mp3     : Line number: 14

05-02 16:41:19.917 25916 25916 I mp3     : Source line:             MediaPlayer.Load(handle, &quot;tq.mp3&quot;);

05-02 16:41:19.917 25916 25916 I mp3     : 

05-02 16:41:19.918 25916 25916 D mp3     : One or more errors occurred.
05-02 16:41:19.918 25916 25916 W System.err: java.lang.RuntimeException: One or more errors occurred.
05-02 16:41:19.936 25916 25916 W System.err:     at com.Bindings.Binding_Fuse_App_FrameCallback.__n_doFrame(Native Method)
05-02 16:41:19.936 25916 25916 W System.err:     at com.Bindings.Binding_Fuse_App_FrameCallback.doFrame(Binding_Fuse_App_FrameCallback.java:14)
05-02 16:41:19.936 25916 25916 W System.err:     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:856)
05-02 16:41:19.936 25916 25916 W System.err:     at android.view.Choreographer.doCallbacks(Choreographer.java:670)
05-02 16:41:19.936 25916 25916 W System.err:     at android.view.Choreographer.doFrame(Choreographer.java:603)
05-02 16:41:19.936 25916 25916 W System.err:     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
05-02 16:41:19.936 25916 25916 W System.err:     at android.os.Handler.handleCallback(Handler.java:739)
05-02 16:41:19.936 25916 25916 W System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
05-02 16:41:19.936 25916 25916 W System.err:     at android.os.Looper.loop(Looper.java:148)
05-02 16:41:19.938 25916 25916 W System.err:     at android.app.ActivityThread.main(ActivityThread.java:5466)
05-02 16:41:19.938 25916 25916 W System.err:     at java.lang.reflect.Method.invoke(Native Method)
05-02 16:41:19.938 25916 25916 W System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
05-02 16:41:19.938 25916 25916 W System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-02 16:41:19.938 25916 25916 F libc    : Fatal signal 11 (SIGSEGV), code 1, fault addr 0xdeadcab1 in tid 25916 (com.mp3)
05-02 16:41:20.056   256   256 F DEBUG   : pid: 25916, tid: 25916, name: com.mp3  &gt;&gt;&gt; com.mp3 &lt;&lt;&lt;
05-02 16:41:21.533 25916 25916 W com.mp3 : type=1701 audit(0.0:8166): auid=4294967295 uid=10229 gid=10229 ses=4294967295 subj=u:r:untrusted_app:s0:c512,c768 reason=&quot;memory violation&quot; sig=11
05-02 16:41:21.565   242   242 E lowmemorykiller: Error writing /proc/25916/oom_score_adj; errno=22
05-02 16:41:21.599  8299  8314 I ActivityManager: Process com.mp3 (pid 25916) has died
05-02 16:41:21.599  8053  8053 I Zygote  : Process 25916 exited due to signal (11)
Process com.mp3 terminated.

quite getting there!

AWESOME!, is working thank you Vegard and Anders. The code is working as follows

MainView.ux

<App Theme="Basic">
    <DockPanel>
        <StatusBarBackground Dock="Top" />
    &lt;JSAudioPlayer.Player ux:Global=&quot;Player&quot; /&gt;

    &lt;JavaScript&gt;


        var MediaPlayer = require(&quot;Player&quot;);


        var handle = MediaPlayer.Create();
        MediaPlayer.Load(handle, &quot;http://patrimonio24.com/site/assets/files/16943/torres_de_quart.mp3&quot;);



        function playme() {
            MediaPlayer.Play(handle);
        }

        module.exports = {
            playme: playme

        }

    &lt;/JavaScript&gt;
   &lt;StackPanel&gt;

        &lt;Button Text=&quot;Play mp3 Audio&quot; Clicked=&quot;{playme}&quot; /&gt;
    &lt;/StackPanel&gt;
&lt;/DockPanel&gt;


Player.uno


using Uno;
using Uno.Collections;
using Uno.Compiler.ExportTargetInterop;
using Fuse;
using Fuse.Scripting;
using Fuse.Reactive;
namespace JSAudioPlayer
{
    public class Player : NativeModule
    {
        public Player()
        {
            AddMember(new NativeFunction("Create", (NativeCallback)Create));
            AddMember(new NativeFunction("Load", (NativeCallback)Load));
            AddMember(new NativeFunction("Play", (NativeCallback)Play));
        }
    static int _playerCount = 0;
    static Dictionary&lt;int, IMediaPlayer&gt; _players = new Dictionary&lt;int, IMediaPlayer&gt;();

    static object Load(Context c, object[] args)
    {

        var player = _players[(int)args[0]];

        var filePath = args[1] as string;

        player.Load(filePath);

        return null;
    }

    static object Play(Context c, object[] args)
    {

        var player = _players[(int)args[0]];
        player.Play();
        return null;
    }

    static object Create(Context c, object[] args)
    {
        var id = _playerCount++;
        _players.Add(id, MediaPlayer.Create());
        return id;            

    }
}

static class MediaPlayer
{
    public static IMediaPlayer Create()
    {
        if defined(Android) return new AndroidMediaPlayer();
        else if defined(iOS) return new iOSMediaPlayer();


    }
}

interface IMediaPlayer
{
    void Load(string filePath);
    void Play();
}

extern(Android) class AndroidMediaPlayer : IMediaPlayer
{

    readonly Java.Object _mediaPlayerHandle;

    public AndroidMediaPlayer()
    {
        _mediaPlayerHandle = Create();
    }

    public void Load(string filePath) { Load(_mediaPlayerHandle, filePath); }

    public void Play() { Play(_mediaPlayerHandle); }

    [Foreign(Language.Java)]
    static Java.Object Create()
    @{
        return new android.media.MediaPlayer();
    @}

    [Foreign(Language.Java)]
    static void Load(Java.Object handle, string filePath)
    @{
        try
        {
            ((android.media.MediaPlayer)handle).setDataSource(filePath);
            ((android.media.MediaPlayer)handle).prepare();
        }
        catch (java.lang.Exception e)
        {
            android.util.Log.d(&quot;android player&quot;, &quot;Failed to load: &quot; + e.getMessage());
        }
    @}

    [Foreign(Language.Java)]
    static void Play(Java.Object handle)
    @{
        ((android.media.MediaPlayer)handle).start();
    @}
}

extern(iOS) class iOSMediaPlayer : IMediaPlayer
{
    public void Load(string filePath) { }
    public void Play() { }
}


Code in GitLab

Hi Guys,

I’ve tried this code in Fusetools version 1.2.1 and get these two errors. Any idea how to fix this?

…/Player.uno(55.36): E4516: Not all code paths return a value
…/Player.uno(55,37): Error E4516: Not all code paths return a value

The package contains a outdated .unoproj structure and Theme=“Basic” should be removed from

Hi Nico,

this indeed is very old code. Have you taken a look at FuseCloud and Fuse.StreamingPlayer? - those could be exactly what you need.

Thanks