Skip to content
This repository was archived by the owner on Jan 2, 2026. It is now read-only.
This repository was archived by the owner on Jan 2, 2026. It is now read-only.

Allow background audio play on iOs #1

@pabloacastillo

Description

@pabloacastillo

Hi there, this port is great it just needs background audio when a iOs device is blocked or the screen turns off.

I saw the code at nstudio has been updated to run in this mode and seems to be an easy fix.
The six line change occurs in in ios/player.ts:

playFromUrl function change this:

let audioSession = AVAudioSession.sharedInstance();
let output = audioSession.currentRoute.outputs.lastObject.portType;

to this:

let audioSession = AVAudioSession.sharedInstance();
audioSession.setCategoryWithOptionsError(
  AVAudioSessionCategoryAmbient,
  AVAudioSessionCategoryOptions.DuckOthers
);
let output = audioSession.currentRoute.outputs.lastObject.portType;

and in playFromFile function change this:

let audioSession = AVAudioSession.sharedInstance();
let output = audioSession.currentRoute.outputs.lastObject.portType;
TNS_Player_Log('output', output);

to this:

let audioSession = AVAudioSession.sharedInstance();
audioSession.setCategoryWithOptionsError(
  AVAudioSessionCategoryAmbient,
  AVAudioSessionCategoryOptions.DuckOthers
);
let output = audioSession.currentRoute.outputs.lastObject.portType;
TNS_Player_Log('output', output);

I hope this helps someone else who has to dig around this issue.

check more information at nstudio/nativescript-audio#19

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions