Ionic Music Controls does not work | Ionic 3 + Ionic Native Media + Ionic Native Music Controls

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I'm using Ionic 3 + Ionic Native Media + Ionic Native Music Controls but music controls doesn't works. Clicking Play / Pause on Music Controls nothing happen. Media streaming works well.

I've installed all cordova plugins required of course.

I've switched ON the 'Audio' option in Capabilities -> 'Background Modes' using XCODE 9.

I'm testing it on iOS (10.3 / 11) simulator and device, and on Android tablet device.

Home.html

 padding>
  
 ion-button (click)="play()">
  play file!

 ion-button (click)="pause()">
  pause file!

Home.ts

  import { Component } from '@angular/core';
    import { NavController } from 'ionic-angular';
    import { Media, MediaObject } from '@ionic-native/media';
    import { MusicControls } from '@ionic-native/music-controls';

    @Component({
      selector: 'page-home',
      templateUrl: 'home.html'
    })    
    export class HomePage {
          file: MediaObject;
          constructor(private musicControls: MusicControls, private media: Media, public navCtrl: NavController) {
          }
          play(){
            this.file = this.media.create('https://archive.org/download/db2007-05-20.rm.flac16/db2007-05-20d1t01.mp3');
            this.file.play();

            this.musicControls.destroy(); // it's the same with or without the destroy 
            this.musicControls.create({
              track       : 'Test track',        // optional, default : ''
              artist      : 'test artist',                       // optional, default : ''
              cover       : '',      // optional, default : nothing
              // cover can be a local path (use fullpath 'file:///storage/emulated/...', or only 'my_image.jpg' if my_image.jpg is in the www folder of your app)
              //           or a remote url ('http://...', 'https://...', 'ftp://...')
              isPlaying   : true,                         // optional, default : true
              dismissable : true,                         // optional, default : false

              // hide previous/next/close buttons:
              hasPrev   : false,      // show previous button, optional, default: true
              hasNext   : false,      // show next button, optional, default: true
              hasClose  : true,       // show close button, optional, default: false

            // iOS only, optional
              album       : 'test album',     // optional, default: ''
              duration : 0, // optional, default: 0
              elapsed : 0, // optional, default: 0
              hasSkipForward : true,  // show skip forward button, optional, default: false
              hasSkipBackward : true, // show skip backward button, optional, default: false
              skipForwardInterval: 15, // display number for skip forward, optional, default: 0
              skipBackwardInterval: 15, // display number for skip backward, optional, default: 0

              // Android only, optional
              // text displayed in the status bar when the notification (and the ticker) are updated
              ticker    : 'Now playing test'
             });
             this.musicControls.subscribe().
                                                
                                                
0 views
0 shares
profilepic.png
manpreet 2 years ago

 

I have this:

radio.ts

import { Component } from '@angular/core';
import { IonicPage, LoadingController, AlertController, Platform } from 'ionic-angular';
import { MusicControls } from '@ionic-native/music-controls';
import { RadioPlayer } from '../../providers/radio-player/radio-player';

@IonicPage()
@Component({
  selector: 'page-radio',
  templateUrl: 'radio.html',
})
export class RadioPage {

  public playing: boolean = false;
  private loadingPopup: any;
  public icono: string = 'play';
  radio = {
    title: "UFM Radio",
    description: "UFPSOcaña",
    url: "http://ufm.ufpso.edu.co:8000/ufm.ogg",
    image: "assets/radioUFM.png"
  };

  constructor(
    private platform: Platform,
    private musicControls: MusicControls,
    public loadingCtrl: LoadingController,
    public alertCtrl: AlertController,
    public myplayer: RadioPlayer,
  ) {

    if (this.myplayer.stream) {
      this.eventPlay(true);
    }
    if (this.platform.is('cordova')) {
      this.myplayer.createNotificationMusic();    // Crear el controlador de musica
      this.musicControls.listen();                // activates the observable above
      this.musicControls.subscribe().subscribe(action => {
        this.eventos(action)                      // Notificacion
      });
    }

  }

  reproductor() {
    (this.playing) ? this.pause() : this.play();    // De acuerdo al estado activa o no la musica
  }

  play() {
    this.loadingPopup = this.loadingCtrl.create({     // Crea el cargando
      spinner: 'dots',
      content: ''
    });
    this.loadingPopup.present();

    this.myplayer
                                                    
                                                    
0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.