I am using Electron 8.0.3 and I am trying to play a custom sound. Here's what I am doing:
const notif = new Notification({
title: 'Finished Download',
body: 'test',
sound: 'vapp/assets/sounds/mighty_sound.mp3',
});
notif.show();
It doesn't seem to play that sound but instead a default macOS sound. I've tried:
Using a absolute path like '/Users/<name>/Desktop/workspace/proj/vapp/assets/sounds/sound.mp3'
Packaging the application so that the sound is bundled
Playing different file types: .wav, .mp3, .aiff
Choosing other macOS sounds that might exist in /System/Library/Sounds
For whatever reason, it plays the same sound.
I have referenced this documentation
My approach was to set the silent attribute of electron's Notification module to true so that the OS sound doesn't play and then use this sound-play npm package to play my own sound.
const showNotification = () => {
new Notification({
title: "Elon Musk is Tesla CEO",
body: "The automaker just got...",
silent: true, //// Disable sound by operating system
}).show();
// Play custom sound
const sound = require("sound-play");
sound.play("./src/quite-impressed.mp3");
};
Related
I have an app in xamarin ios in which I want to play alarm tone when notification fires and stop when user dismiss the notification. How can I achieve this ?
Take a look at UNNotificationSound , it is used to customize sound played upon delivery of a notification.
For local notifications, assign the sound object to the sound property of your UNMutableNotificationContent object.
Sample code
var content = new UNMutableNotificationContent();
content.Title = "Title";
content.Sound = UNNotificationSound.GetCriticalSound("a.aiff");
var trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(5, false);
var request = UNNotificationRequest.FromIdentifier("a", content,trigger);
UNUserNotificationCenter.Current.AddNotificationRequest(request, null);
Notice
Place the sound file in the following locations :
The /Library/Sounds directory of the app’s container directory.
The /Library/Sounds directory of one of the app’s shared group container
directories.
The main bundle of the current executable.
The sound must be in one of the following audio data formats:
Linear PCM
MA4 (IMA/ADPCM)
µLaw
aLaw
You can package the audio data in an aiff, wav, or caf file.
Sound files must be less than 30 seconds in length.
If the sound file is longer than 30 seconds, the system plays the default sound instead.
The original video is "Sample Video 5" from https://www.appsloveworld.com/download-sample-mp4-video-mp4-test-videos/.
My /home/vagrant/Code/example/public/hls_hls.keyInfo is:
https://example.com/hls.key
/home/vagrant/Code/example/public/hls_hls.key
467216aae8a26fb699080812628031955e304a66e9e4480f9b70d31d8fe94e9a
My /home/vagrant/Code/example/public/hls_hls.key was generated using PHP: hex2bin('467216aae8a26fb699080812628031955e304a66e9e4480f9b70d31d8fe94e9a')
The ffmpeg command for encrypting the video as HLS playlist with "ts" files:
'/usr/bin/ffmpeg' '-y' '-i' 'storage/app/sample_media2/2020-02-27/Sample_Videos_5.mp4'
'-c:v' 'libx264' '-s:v' '1920x1080' '-crf' '20' '-sc_threshold' '0' '-g' '48'
'-keyint_min' '48' '-hls_list_size' '0'
'-hls_time' '10' '-hls_allow_cache' '0' '-b:v' '4889k' '-maxrate' '5866k'
'-hls_segment_type' 'mpegts' '-hls_fmp4_init_filename' 'output_init.mp4'
'-hls_segment_filename' 'storage/app/public/test/output_1080p_%04d.ts'
'-hls_key_info_file' '/home/vagrant/Code/example/public/hls_hls.keyInfo'
'-strict' '-2' '-threads' '12' 'storage/app/public/test/output_1080p.m3u8'
Then, I know from https://caniuse.com/#search=hls that Windows Chrome won't be able to play the HLS video without a library, so I use https://github.com/video-dev/hls.js/, and Windows Chrome successfully plays the encrypted video!
However, iOS Safari is unable to play it (with or without the hls.js library).
On iOS Safari, when I try to play the video, I see just a quick glimpse (less than a second) where the screen shows 0:15, so it must be reading and decrypting enough to know the correct duration of the video.
So, to debug, I log events:
const nativeHlsEvents = ['play', 'playing', 'abort', 'error', 'canplaythrough', 'waiting', 'loadeddata', 'loadstart', 'progress', 'timeupdate', 'volumechange'];
$.each(nativeHlsEvents, function (i, eventType) {
video.addEventListener(eventType, (event) => {//https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement
console.log(eventType, event);
if (eventType === 'error') {
console.error(video.error);//https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/error
}
});
});
I see in the console log:
loadstart, {"isTrusted":true}
progress, {"isTrusted":true}
play, {"isTrusted":true}
waiting, {"isTrusted":true}
error, {"isTrusted":true}
video.error, {}
I don't know how to find more details about the error.
Note that even though Windows Chrome successfully plays the video, it too shows warnings in the console log:
{"type":"mediaError","details":"fragParsingError","fatal":false,"reason":"TS packet did not start with 0x47","frag":{"...
{"type":"mediaError","details":"fragParsingError","fatal":false,"reason":"no audio/video samples found","frag":{...
Where is my problem?
I would need to buy a newer iPhone.
I see at https://en.wikipedia.org/wiki/IPhone_6#Software and https://support.apple.com/guide/iphone/supported-iphone-models-iphe3fa5df43/ios that “6s” is the oldest hardware that iOS 13 supports, and https://caniuse.com/#search=hls says HLS needs >=13.2.
Iphone devices not supported media source extension.
You should by user agent checking has iphone?
If be right, you should use iphone native video player for play hls video type or more video type
I have an app that uses Firebase Messaging to send notifications, and I have a set of sounds added to my xcode project resources, to play on the device.
I send the notification to users subscribed to specific topics, from my server like this:
"apns": {
"headers": {
"apns-priority": "10",
},
"payload": {
"aps": {
"alert": {
"title": titleMessage,
"body": bodyMessage,
},
"sound": 'alert.wav',
},
},
}
Now the sound "alert.wav" plays fine on the device, when the notification is received.
What I want to do is inside my app:
I want to allow users to change the notification sound, from different sets of sounds.
Example: Option to play sound from: set 1, or set 2. and I would have them in my app as seperate folders with the same file names.
Is this possible in iOS? and how can I achieve it in react native?
I was able to do it, and this is how:
1. Added the sounds file in xcode, in my app resources.
Just added a link to the folder that contains all my sounds, and did not link each file, as I want the app to play sounds later from: The "/Library/Sounds directory".
2. Used rn-fetch-blob to copy sounds and replace them.
By using rn-fetch-blob I was able to create the /Library/Sounds directory and then move the sounds from MainBundleDir to /Library/Sounds, where the app will be looking for sounds when a notification is received.
I created an interface to allow users to replace these sounds.
//Function: setup sounds
setupSounds(){
//sounds directory
const dirs = RNFetchBlob.fs.dirs
const soundsDir = dirs.CacheDir.replace('Caches','Sounds')
//Check if has sounds directory
RNFetchBlob.fs.isDir(soundsDir).then((isDir) => {
//create directory
if(!isDir) RNFetchBlob.fs.mkdir(soundsDir)
})
//Add the sound file to /Library/Sounds
RNFetchBlob.fs.writeFile(soundsDir+'/default.wav', dirs.MainBundleDir + '/sounds/jingle.wav', 'uri');
}
Now if the app received a notification with sound: 'default.wav' the app will play default.wav which is a copy of jingle.wav.
Are ios native sounds Ringtone, Text Tone, New Mail, etc. available to play directly via Cordova (with the native audio plugin, for instance)?
All the examples I can find require a direct URL to the sound file in your www/audio directory, like this:
//preload the media
window.plugins.NativeAudio.preloadComplex( 'music', 'audio/music.mp3', 1, 1, 0, function(msg){
}, function(msg){
console.log( 'error: ' + msg )
});
window.plugins.NativeAudio.loop( 'music' );
Can't they be accessed and played directly? Let's say the iphone has Text Tone preference set to "Aurora." I'd want the app to be able to trigger the "Text Tone," which would play the sound "Aurora".
You can access ringtones now via this plugin: cordova-plugin-native-ringtones.
I am creating a mobile app using react-native where I schedule local notifications which play a sound when the notification is fired. I am using PushNotificationIOS API in react-native to handle local notification in iOS. I have been using react-native version 0.24 till now and the sound use to play as expected. I recently updated to latest version 0.30 and the sound doesn't play now on receiving notification. I am not sure what is wrong as nothing has been changed w.r.t. playing sound using PushNotificationIOS since 0.24. I have confirmed that:
The sound file is present in the Xcode project
It is present in the Copy Bundle Resources in Xcode
The sound file is actually present in the app by playing the sound file using react-native-sound package in the simulator
The soundName is set correctly in the local notification. I printed the notification.getSound() and got the right name.
I even tried with playing the default sound by setting the soundName to default but still no sound. Below is how I am scheduling the local notification:
PushNotificationIOS.scheduleLocalNotification({
fireDate: time,
alertBody: alertBody,
soundName: 'default',
userInfo: info,
category: category
});
index.ios.js file
class TestLocalNotification extends Component {
componentDidMount() {
PushNotificationIOS.requestPermissions()
}
scheduleLocalNotification = () => {
console.log('Scheduling local notification')
PushNotificationIOS.scheduleLocalNotification({
fireDate: Date.now() + 60000,
alertBody: 'Notificaiton',
soundName: 'default'
});
}
render() {
return (
<TouchableOpacity onPress={this.scheduleLocalNotification}>
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
</View>
</TouchableOpacity>
);
}
}
The problem can be reproduced by following steps
Create a new project by giving command react-native init TestLocalNotification
Copy the above code for the component in the index.ios.js file
Import PushNotificaionIOS and TouchableOpacity from react-native
Run the app. Click the text Welcome to React Native and go to home screen by pressing shift + cmd + h . Observe that a local notification after a minute but no sound is played.
Please advice on how I can debug and fix this problem. Thanks!