0

I'm trying to create an Android application with Nativescript. So far I'm doing great, except for one thing (and - considering this is an app for listening podcast - maybe the most important one).

To reproduce mp3 files in my app, I'm using a plugin quite famous, named nativescript-audio. It works great, except that doesn't show any control when phone is in Lock Screen. Which is something I want to give to user.

Reading some android developer documentation, I found out I might need a MediaSession, and then add some icons with actions and write some callback functions to manipulate the player.

Problem is: in Nativescript, how can I do that?

this.session = new android.media.session.MediaSession(
    android.content.Context,
    'My Media Session'
)

This is the snippet I used in my player TypeScript class. But not working, because I receive this error:

Error: Cannot marshal JavaScript argument function () { [native code] } at index 0 to Java type.

Anyone with this problem before willing to help me? Thanks a bunch!

Carbamate
  • 77
  • 1
  • 7

1 Answers1

1

You should pass a valid context, you are passing the context class definition itself.

import { android as androidApp } from "tns-core-modules/application";

this.session = new android.media.session.MediaSession(
  androidApp.context,
  'My Media Session'
)
Manoj
  • 21,753
  • 3
  • 20
  • 41
  • Thanks a bunch. Although I'm still not able to do some things I'd like (like properly set functions with `setCallback`) this was a huge help. Thank you. – Carbamate Apr 07 '19 at 16:15