sound.Play() is not playing custom sound file in Garry's Mod - lua

No custom sound files are played, but in-game sound files are played.
Sound file has 44100Hz
I have tried stereo and mono
mp3 and ogg I have also tried
local soundFile = "addons/testaddon/sound/testsound.wav"
hook.Add("KeyPress", "myTestAddon", function(ply, key)
if key == IN_JUMP then
sound.Play(soundFile, ply:GetPos(), 75, 100, 1)
print("Test")
end
end)

This should be [...] a file path relative to the sound/ folder.
https://wiki.facepunch.com/gmod/sound.Play
In your case just use "testsound.wav".

Related

Roblox studio Sound max distance not working

I am trying to create a script so that when a part touches another it plays sound from a parent called speaker, I am trying and have set the max distance to 50 studs but it's not working
Here is the script:
local announce = game.Workspace.Announce
local vehicleSeat = game.Workspace["AXP Series(tong's mod)"].VehicleSeat
local speaker = game.Workspace.Speaker
local sound = game.SoundService.Sound
vehicleSeat.Touched:Connect(function(otherPart)
if otherPart == announce then
sound.Parent = speaker
sound:Play()
end
end)
enter image description here
Based on this DevForum conversation, it sounds like you need to double check that the Sound is a child of a Part, not a Model. When the sound is Parented to a Model, you can hear the sound everywhere.
This is confirmed in the Sound documentation :
A sound placed in a BasePart or an Attachment will emit its sound from that part's BasePart.Position or the attachment's Attachment.WorldPosition
...
A sound is considered "global" if it is not parented to a BasePart or an Attachment. In this case, the sound will play at the same volume throughout the entire place.

How to play alarm tone in xamarin ios when local notification fires at specific time

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.

Hls stream url wont play in AVPlayer

I am trying to play an hls live stream from a url that looks like this: "http://ip.address:port/my%20video.m3u8". Whenever the url does not involve any spaces the video plays fine otherwise it does not play. There is no error logged from the player but the player itself is just a black screen. I enabled "Allow Arbitrary Loads" and still no dice. When I try loading the urls with spaces in safari the video will play. Here is my code to load and play the video:
DispatchQueue.main.async {
var player = AVPlayer(url: url!)
var playerLayer: AVPlayerLayer!
playerLayer = AVPlayerLayer(player: player)
playerLayer.videoGravity = .resize
self.videoView.layer.addSublayer(playerLayer)
playerLayer.frame = self.videoView.bounds
player.play()
}
What I also find odd is when I try sending the stream to a AVPlayerViewController the player pops up but does not play. Here is how I am sending it to the view controller:
DispatchQueue.main.async {
let player = AVPlayer(url: urlTwo)
let playerController = AVPlayerViewController()
playerController.player = player
present(playerController, animated: true) {
player.play()
}
}
Please check the m3u8 file may be the content in m3u8 have some directory issue. .ts segment and .key file was mentioned in m3u8 file. And when you pass m3u8 to avplayer it fetch the key and .ts file automatically and decrypt the .ts with the mentioned key. Just cross check you m3u8 for key and .ts file.
Also, .key and .ts files need to be in same folder along with m3u8 otherwise it will not fetch and player keep looking for the key and ts.
#EXTM3U
#EXT-X-TARGETDURATION:12
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-VERSION:4
#EXT-X-KEY:METHOD=AES-128,URI="title.key"
#EXTINF:10.0100,
#EXT-X-BYTERANGE:943584#0
title.ts
Something like this.
Note: Sometimes m3u8 and key file have additional encryption which you need to decrypt on run time. I suggest open it in text editor and see if you can see something like given structure above. If it has something unreadable then you need to decrypt it first on run time. If you are using local server and loading file from cache then save the m3u8 file after decryption with Encoding.utf8 and .key file with Encoding.macOSRoman. Otherwise it will not gonna work. Cheers.

Failed to Create Sound

Very simple issue but I have no idea if anyone can help me with it. Perhaps it is a bug? I simply want to load this order but get the warning that WARNING: C:\Users\Usuario\Documents\Corona Projects\BalloonTap\game.lua:259: audio.loadSound() failed to create sound 'audio/pop.wav´.
The directory of the audio of the audio file is C:\Users\Usuario\Documents\Corona Projects\BalloonTap\audio
The code is:
balloonPop = audio.loadSound( "audio/pop.wav")
Any possible fixes? I have tried different audio files and renaming file. I have tried putting it in the main folder and just saying balloonPop = audio.loadSound( "pop.wav") but that fails as well.
When sounds are not loading in Corona, it is a good idea to check that the file can be found:
local filename = "audio/pop.wav"
if system.pathForFile( filename , system.ResourceDirectory ) == nil then
print("WARNING: cannot find audio file "..filename )
end
The fact that the sound could not be created suggests, however, that this is not the problem. From the Audio Usage/Functions Guide:
Cross-platform .wav files must be 16-bit uncompressed.
Is your sound file in the correct format?

Swift 2 - m4a file won't play on iOS

I'm trying to play an m4a file on an iOS device programatically. The file is downloaded from a server and stored. When the user presses a button, it is played. The file, when copied from the device to OSX does play fine. I am using the code
var player:AVAudioPlayer = AVAudioPlayer()
func playAudio(sender: UIButton!) {
let audioPath = FileUtils.getPath(audioPaths[sender.tag])
print("PATH " + audioPath)//The printed path IS DEFINETLY correct
do{
player = try! AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath))
player.prepareToPlay()
player.play()
}
}
The path is correct so I'm not sure why it won't work. Could it be the format (even though it plays on OSX)?
An example file: https://www.dropbox.com/s/csewwg6n9vzan5z/131015-08%3A13%3A30.m4a?dl=0
That file won't play on iOS because it's encoded in AMR NarrowBand, which is no longer supported.
I would try re-encoding the m4a files as AAC, or switch to mp3.
It's likely just a feature of the way this m4a file is compressed. The simple fact is that not every m4a file, even if it is a perfectly valid file, will play on your device. (For example, perhaps this file is very compressed.) And to make things more complicated, it differs from device to device! And to make things even more complicated, the file might play in the Music app but not in an AVAudioPlayer!!
To test this theory, recode the file as a more middle-of-the-road m4a and see if that plays.

Resources