如何在预定通知中播放我自己的声音?

问题描述 投票:0回答:1

我试图在我的应用程序中应用预定通知,它的工作很好,但没有声音,所以我需要帮助的两件事

1) 如何播放一个声音,并使与我自己的MP3,我想发挥?

2)如果我有一个几次如何修改代码,每次发送本地通知?

const times = ['1:15 AM', '3:15 PM', '6:00 PM', '8:25 PM', '11:45 PM'];

const localNotification = {
    title : 'Testing',
    body : 'The body ',
    data: { name : 'This is the data'},
    ios : {
      sound : true,
      _displayInForeground  : true
    },
    ChannelAndroid : {
      name  : 'Sound',
      sound : true,
      vibrate : [ 0, 250, 250, 250 ]
    }
  }


 const  schedulingOptions = {
    time : (new Date()).getTime() + 5000,
  }


  const currentTime = `${new Date().getHours()}:${new Date().getMinutes()}`;
  console.log(currentTime);
 const pushTime = '1:52';
 if (currentTime === pushTime) {
  Notifications.scheduleLocalNotificationAsync(localNotification, schedulingOptions);
}
react-native notifications expo scheduling
1个回答
0
投票

你可以简单地做到这一点,使用一个名为 "react-native-notification-sounds "的包。请通过链接并按照说明操作。

https:/github.comsaadqbalreact-native-notification-soundsblobmasterREADME.md。

import NotificationSounds, { playSampleSound } from 'react-native-notification-sounds';
NotificationSounds.getNotifications().then(SoundsList => {
    console.warn('SOUNDS', JSON.stringify(SoundsList));
    playSampleSound(SoundsList[1]); 
});
© www.soinside.com 2019 - 2024. All rights reserved.