I have an application using AVFoundation that plays use an mp3 sound file as a sound effect. It's recorded length is 90 seconds long. However, I play it repeatedly, on and off dependant upon varying things, for different lengths of time by utilising the tickingSounds.play() and tickingSounds.stop(). It seems however once I get to 90 seconds that it won't play anymore. I am assuming the play() command resumes from where I last stopped it?
My question is how do I reset it play position or am I missing something else?
You should set:
numberOfLoops
Set the Property numberOfLoops to -1 and it would go into infinite loop.
numberOfLoops
The number of times a sound will return to the beginning, upon reaching the end, to repeat playback.
#property NSInteger numberOfLoops Discussion A value of 0, which is the default, means to play the sound once. Set a positive integer value to specify the number of times to return to the start and play again. For example, specifying a value of 1 results in a total of two plays of the sound. Set any negative integer value to loop the sound indefinitely until you call the stop method.
Availability Available in iOS 2.2 and later. Declared In AVAudioPlayer.h
Related
How do I a produce an infinite loop using a JFugue pattern. I tried the following
while loop
for loop with a high counter
In both cases, weird sounds get produced which are overlapped. When I run with a small counter like 10 in a for loop, it works fine.
I need a pattern to run infinitely until the player is stopped by calling player.close() by an user action (say from UI).
There's not a specific way to make a pattern run forever. This is partly because JFugue compiles music strings into MIDI code, so a pattern that ran forever would just be a infinitely-long MIDI file. Of course, if you use a specific number of times to repeat a pattern, the pattern could be too long or too short for your needs. The best option might be to look into JFugue's RealtimePlayer class, and create a separate thread that keeps playing sections of the metronome pattern while the thread is still active.
Let me know if that helps you get on the right path!
I am calling player.load(protocol, 17800) for live audio stream (duration Infinity). I want to start 17800 seconds after the timestamp of the first segment based on (#EXT-X-PROGRAM-DATE-TIME).
The player is not starting in 17800 seconds. I am off by about 7 minutes. The playlist manifest is 5 hours long. I want to start close to live but not necessarily at the live point. Is there a way to do this?
I do not know what opt_initialTime is relative to? I assume the first segment of the playlist that is pulled. Can someone from Google explain how the google cast media player handles that second parameter of load?
Based from this documentation, opt_initialTime is the time from which to start the playback in seconds. This parameter is used in load and preload methods.
From this link, it discussed how are the load(opt_protocol, opt_initialTime) and preload(opt_protocol, opt_initialTime) supposed to work in the Media Player Library.
Our testing shows that load with an initial time specified works. Preload with an initial time works by downloading segments as specified by the initial time. If that is then followed by a load then that takes precedent and will start the playback from the beginning.
I have to use the noted combination of tools, so suggestions that amount to "don't do that" are not helpful (-:
I can find no reliable way to determine the framerate of a video loaded into a WMP control. Is there some known way to get this value? It's such a basic piece of info that I can't believe I'm not missing something.
In theory I can instance IWMPMedia3 and set that to [player].currentmedia then ask for .GetAttributeByType("framerate", "", 0), but apparently there is some state that the player/media must be in for that to work, and I can't determine when that state exists.
In the IDE, when I try to get the attribute it always fails with Invalid procedure call or argument. I open the debug window and test whether the correct objects are instantiated -- they are. Then I can continue and I have the correct framerate. Clearly that won't work in production. (-:
It's not just waiting that does the trick -- I must actually debug test for Nothing on the objects to get it to proceed.
It appears the framerate item does not get initialized immediately after you set a source video to the control. I tried to wait and call DoEvents and at first found no reliable way to get it working. Displaying a message box and waiting 30 seconds sometimes did it, but not always.
I then decided to examine the attribute by code, and to my surprise, simply checking using getAttributeCountByType() seems to initialize the item without waiting a single millisecond.
In the following code, if the checkbox is enabled, which calls getAttributeCountByType(), the function always succeeds. I tried with AVI, MPEG and MP4 files and it worked on Windows 7. If the checkbox is not checked, it always fails with all types of video files:
WindowsMediaPlayer1.URL = Text1.Text
Dim media As IWMPMedia3
Set media = WindowsMediaPlayer1.currentMedia
If Check1.Value = vbChecked Then
Label1.Caption = "media.getAttributeCountByType " & media.getAttributeCountByType("framerate", "")
End If
MsgBox "Frame Rate = " & media.getItemInfoByType("framerate", "", 0)
So I'm playing around with a tutorial script, and I have a turret added that follows the player's movement. This turret should be shooting at the player every few seconds. Before I added collisions or timed shots or anything like that, I found out that the bullet shots actually aren't being shown. So I set it to a key press just to test, and nope, not working.
Full Code
Anything you see wrong? NOTE: I don't get an error when I run it, the bullets just don't show up!
love.keyreleased(key) treats the shift key as a separate and independent key so "X" will never happen. Instead use "x" to trigger a shot.
function love.keyreleased(key)
if key == 'x' then
shoot()
end
end
Once that is fixed you will have issues in your collision detection:
player is not being used as an array as line 52 for ii, vv in ipairs(player) do suggests.
There is nothing stopping a bullet from having a negative velocity and hitting a player or a player being hit by more than one bullet and so they may be added to the remEnemy and remShot table multiple times which will mess up deleting later.
The index shifts that happen when you delete an entry (mentioned by Etan Reisner) also exist.
For your use case, marking an object to be removed by adding it to a set seems like the best approach to me:
local remShots = {}
then if there is a collision or the bullet has negative velocity then
remShots[i] = true
and to remove, iterate in reverse to avoid shifted indices.
for i=#enemyShots,1,-1 do
if remShots[i] then
table.remove(enemyShots, i)
end
end
Performance
A table.remove shifts all the elements above the index down to fill the gap. In the code here the loop removes multiple elements so they are shifted more than once, but as long as your tables aren't huge, this removal process is fine.
I'm note sure what you were going for with the first bullet point, but you can also use the remPlayer to avoid checking for collisions with players that have already been marked for removal when you get that worked out:
if not remPlayer[ii] and CheckCollision...
Making a small app, and I want a function to execute 50% of the time. So if I were to dbl click the exe half the time the function would execute, and the other half it wouldn't. I can't seem to find anyway to easily do this, the one solution I tried seemed to determine the chance on compile rather than on run. Thanks in advance!
Generate a random decimal number between 0 and 1. If it is greater than 0.5 run, if it is less than or equal to 0.5 do not run.
Don't forget to seed the randomizer! Otherwise it will always give you the same value every time. You seed it using "Randomize Timer", e.g.:
Private Sub Main()
Randomize Timer
If Rnd > 0.5 Then
ExecuteFunction ()
End If
End Sub
For example:
Private Sub Main()
If Rnd > 0.5 Then
ExecuteFunction ()
End If
End Sub
If you want it to randomly run, others have already provided that solution. If you want a more deterministic behavior (it must run exactly every second time), you will need to store state between executions.
You can save the state in either the registry or on the file system by (for example) attempting to read an integer from a file (set it to zero if the file's not there), add 1 and write it back to the same file.
If the number written back was even, run your function otherwise exit.
That way, you'll alternate between execute and don't-execute.