Choose the stream volume


#1

Hello,
When the activity is launch. I want to change the volume media when I press the button volume.
But that change the alarm volume and not the media volume.
Could you tell me how to resolve the problem ?
Cordially


#2

Please share more details like,

  • Code sample
  • Plugin you are using, if any
  • Platform

#4

I use the template drawer navigation ng.
With the language angular and typescript.
But that’s not the problem.
You know in Snapchat when you click on the button “volume +” for example, that increase the media volume and not the call volume.
I want to make the same in my code.
In Android, the line code to make it is :
setVolumeControlStream(AudioManager.STREAM_MUSIC);


#5

You seem to know the solution already. Incase if you are looking for exact code, it will be

import * as app from "application";
declare var android;
...
...
app.android.foregroundActivity.setVolumeControlStream(android.media.AudioManager.STREAM_MUSIC);

#6

Ok. Thank you very much.
And do you know the code for ios ?


#7

I think this stream switch is not applicable for iOS, if you are playing media iOS will automatically identify and increase the media volume.


#8

Ok.
I don’t play a media. But the application is a game. So it’s better if the media volume changes and not the call volume.
But if that not exist in IOS, it’s not grave.


#9

Hello,
When I write this code. I have the error :
TypeError: Cannot read property ‘setVolumeControlStream’ of undefined
Could you tell me what is the problem ?


#10

Are you saying it’s a TypeScript error? It should not as the type will be any but since it does you can just it to any.


#11

So what should I do ?


#12

As I mentioned already cast it to any if its a TypeScript error.


#13

Ok but I don’t know where set the any ?
That is my code :

import { Component, OnInit } from "@angular/core";

import { EventData } from "tns-core-modules/data/observable";
declare var android;

@Component({
    selector: "Connexion",
    moduleId: module.id,
    templateUrl: "./Connexion.component.html"
})

export class ConnexionComponent implements OnInit {

    constructor() {
app.android.foregroundActivity.setVolumeControlStream(android.media.AudioManager.STREAM_MUSIC);
    }

    ngOnInit(): void {

    }
}

#14

Ok but I don’t know where set the any ?
That is my code :

import { Component, OnInit } from "@angular/core";

import { EventData } from "tns-core-modules/data/observable";
declare var android;

@Component({
    selector: "Connexion",
    moduleId: module.id,
    templateUrl: "./Connexion.component.html"
})

export class ConnexionComponent implements OnInit {

    constructor() {
app.android.foregroundActivity.setVolumeControlStream(android.media.AudioManager.STREAM_MUSIC);
    }

    ngOnInit(): void {

    }
}

[/quote]


#15

Try

(<any>app.android.foregroundActivity).setVolumeControlStream(android.media.AudioManager.STREAM_MUSIC);

#16

I try but the probleme is the same.


#17

I try but the probleme is the same


#18

Can you reproduce the issue with Playground?


#19

This is the code in playground :

import { Component, OnInit } from "@angular/core";
import * as app from "application";

declare var android;

@Component({
    selector: "Home",
    moduleId: module.id,
    templateUrl: "./home.component.html",
    styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {

    constructor() {
        app.android.foregroundActivity.setVolumeControlStream(android.media.AudioManager.STREAM_MUSIC);
    }

    ngOnInit(): void {
    }
}

And there is not issues with the code.
I don’t understand what is the problem


#20

This is the code in playground :

import { Component, OnInit } from "@angular/core";
import * as app from "application";

declare var android;

@Component({
    selector: "Home",
    moduleId: module.id,
    templateUrl: "./home.component.html",
    styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {

    constructor() {
        app.android.foregroundActivity.setVolumeControlStream(android.media.AudioManager.STREAM_MUSIC);
    }

    ngOnInit(): void {
    }
}

And there is not issues with the code.
I don’t understand what is the problem


#21

Could you help me please ?