Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localnotifications play audio does not wrk properly #1254

Closed
anivaisu opened this issue Mar 26, 2017 · 2 comments
Closed

Localnotifications play audio does not wrk properly #1254

anivaisu opened this issue Mar 26, 2017 · 2 comments

Comments

@anivaisu
Copy link

Hi,
I am beginner in ionic 2.

Here is my JSON File

"notifications" : {
"0" : {
"FROM" : 1,
"MSG" : "Admin Saravanan has sent new circular (Message from admin) ",
"RECEIVE_TIME" : "2017-03-18 06:17:26",
"SEND_TIME" : "2017-03-17 02:38:01",
"STATUS" : "ON",
"TO" : "ALL",
"TYPE" : "EVENT"
},
"1" : {
"FROM" : 1,
"MSG" : "New visitor muruganantham.k.m checkin your flat.",
"RECEIVE_TIME" : "2017-03-23 06:33:06",
"SEND_TIME" : "2017-03-23 11:45:26 am",
"STATUS" : "ON",
"TO" : "2",
"TYPE" : "VISITORS"
}
}

Here is my app component.

import { Component } from '@angular/core';
import { Platform,AlertController } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';
import { HomePage } from '../pages/home/home';
import { AngularFire} from 'angularfire2'
import { LocalNotifications} from 'ionic-native';
import { AudioProvider } from 'ionic-audio';
import { FormBuilder } from '@angular/forms';
@component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage = HomePage;
audio;
notifications=[];
Alarmcheck;
//playSelectedTrack:any;
constructor(private FormBuilder:FormBuilder, private _audioProvider: AudioProvider,private AlertController:AlertController,platform: Platform,public af:AngularFire,) {
this.audio = new Audio();
this.audio.src='https://ia800406.us.archive.org/16/items/JM2013-10-05.flac16/V0/jm2013-10-05-t30-MP3-V0.mp3';
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
StatusBar.styleDefault();
Splashscreen.hide();

   var arr=[];
  this.af.database.list('/notifications').subscribe(data=>{
    console.log("firebase collection");
    arr=data;

    for(var i in arr)
    {
      if(arr[i].STATUS === 'ON')
      {
         var key=arr[i].$key;
         console.log("ALARM CHECKED");
         console.log(this.Alarmcheck);
         if(this.Alarmcheck === undefined || this.Alarmcheck === 'OFF') 
          {
            console.log("opened");
            console.log(arr[i].STATUS);
           LocalNotifications.schedule({
                title: "Test Title",
                text: "You have new notification",
                at: new Date(new Date().getTime() + 5 * 1000),
                sound:this.playSelectedTrack(),
            })
             LocalNotifications.on("click", (notification, state) => {
              let alert = this.AlertController.create({
                        title: "Notification Clicked",
                        subTitle: "You just clicked the scheduled notification",
                        buttons: [{
                           text: "exit?",
                        handler: () => { this.pauseSelectedTrack(key) }
                        }]
                    });
              alert.present();
            });
          }
      }
   }
  })
});

}

schedule()
{
console.log("Notifications received");
LocalNotifications.schedule({
title: "Test Title",
text: "You have new notification",
at: new Date(new Date().getTime() + 5 * 1000),
sound:this.playSelectedTrack(),
})

}

playSelectedTrack():any{
console.log("audio play");
this.audio.play();

}
pauseSelectedTrack(key):any{
console.log("audio Paused");
var form1 = this.FormBuilder.group({
STATUS:['OFF']
});
var value=form1.value;
console.log("Value");
console.log(form1.value);
this.af.database.list('/notifications').update(key,value)
// console.log(this.audio.pause);
this.audio.pause();
this.audio.src="";
this.Alarmcheck="OFF";
}
}

My app is received Notifications based on condition When status is ON.Receive first notifications and backround play audio.when click on notification display alert and click the OK button.Pause this audio also update status OFF.and receive another notification does not play audio file.

How to fix this issue.

Kindly advice me,

Thanks

@rwillett
Copy link
Collaborator

Fill out the template in #1188 as its unclear what you are trying to do.

@rwillett
Copy link
Collaborator

Closed as no update from original poster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants