How To Use Play In Background Function

broken image


To enable background audio, you must add the background media playback capability to the app manifest file, Package.appxmanifest. To add capabilities to the app manifest using the manifest designer In Microsoft Visual Studio, in Solution Explorer, open the designer for the application manifest by double-clicking the package.appxmanifest item. Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML. Now, YouTube does let you use its video app to play music in the background but there's a caveat: you need to be a Premium subscriber in order to take advantage of that feature. Of course, you can. This is an example of executing a function in the background. I was searching for an option to run a function in background along with the normal execution flow. The main execution will continue in the same flow without waiting for the background function to complete and the function set for background execution will continue.

Music, Sounds, ON PLAY and Using the Soundcard

This tutorial is about statements used to play music, create sounds
and the ON PLAY statement.

BEEP
ON PLAY.. GOSUB
PLAY
SOUND
Using the Microphone
Using the Soundcard to Produce Sound
BEEP

Use the BEEP statement to make
the computer beep once.

Use the ON PLAY statement to make a program
call a subroutine each time there are less
than the specified amount of notes left
to play. For example: if a program
has to play the notes A, B, A and B it
has to play 4 notes and if the following
lines are used in the program:
ON PLAY(2) GOSUB 1, the program will
go to line number 1 as soon as it
has played 'ABA' because only the
last note (B) is left to play because
there were less than 2 notes left.

Use the RETURN statement to return
to the point in the program when
the subroutine was called.

Use PLAY OFF to turn ON PLAY off.
Use PLAY ON to turn ON PLAY on.
Use PLAY STOP to pause ON PLAY.

How To Use Play In Background Function
Example:

ON PLAY(3) GOSUB 1
PLAY ON4
CLS
DO
PLAY 'CDEFGAB'
LOOP
END

1 PRINT '*';
RETURN

PLAY

Use the PLAY statement to play music.
Here are the commands for the PLAY statement:

C, D, E, F, G, A and B are the notes.

Ooctave = Set the octave.
< = Down one octave.
> = Up one octave
Nnote = Play a note (range: 0-84, 0 = pause.)

Llength = Set the length of a note (range: 1-64, 1 = A whole note.)
Tnumber of quarter notes per minute (range: 32-255.)

ML = Play the full length set by L (legato.)
MN = Play 7/8 of the length set by L (normal.)
MS = Play 3/4 of the length set by L (staccato.)

Pnumber of quarter notes, range: 1-64.

MB = Play music in background, this will let the computer play
music while the program continues with other things.
MF = Play music in foreground, the program will be paused
until the music is done playing.

Example 1:

PLAY 'CDEFGAB'

Example 2:

PLAY 'L16 ML CDEFGAB'

Use the SOUND statement to make sounds.
The frequency can range from 37 to 32767
and the duration from 0 to 65535.
This how SOUND is used:
SOUND frequency, duration

Example:

SOUND 37, 1

Using the Microphone:
How to use play in background functions

Use OUT to tell the soundcard to return one
sample of input from the microphone like this:
OUT base address + 12, 32

To read the sample returned use INP like this:
INP base address + 10

The volume for the microphone is set like this:
OUT base address + 4, 10
OUT base address + 5, volume
The range for the volume is 0 to 7.

To get the volume for the microphone, use INP like this:
OUT base address + 4, 10
INP base address + 5

Base address + number refers to the address
of an I/O port which is the base address plus number.

Example:

DEFINT A-Z

'Set the volume for the microphone.
OUT 548, 10
OUT 549, 7

x = 0
SCREEN 12: CLS
PSET (0, 128), 2
DO
IF x = 639 THEN
x = 0
CLS
PSET (0, 128), 2
ELSE
'Tell soundcard to return one sample from the microphone.
OUT 556, 32
LINE -(x, INP(554)), 2
x = x + 1
END IF
LOOP

Using the Soundcard to Produce Sound:

Use OUT to tell the soundcard that a sample
has to be sent to the speakers like this:
OUT base address + 12, 16

Use OUT base address + 12, sample to
send one sample to the speakers.

On computers which run above a certain speed it is possible
that new instructions are sent while producing sound while the
soundcard is still processing earlier instructions.
Use WAIT base address + 12, 128, 128 to wait until
the soundcard is ready for new instructions.

Before producing sound, the soundcard has to be reset like this:
OUT base address + 6, 1
OUT base address + 6, 0

The volume for both speakers is set separatly but has
to be sent as one value and is returned as one value.
The range for the volume is 0 to 15.
The value that has to be sent to set the volume is calculated like this:
volume = (left speaker volume * 16) + right speaker volume

This is how the volume for both speakers is set:
OUT base address + 4, 34
OUT base address + 5, volume

Developmentwarrior cats the games. To get the volume for both speakers, use INP like this:
OUT base address + 4, 36
INP base address + 5

The value for the volume that is returned is converted to two
separate volumes for both speakers like this:
left speaker volume = volume 16
right speaker volume = volume - (left speaker volume * 16)

Example:

Help and contribute learning. 'Reset the soundcard.
OUT 550, 1
OUT 550, 0

'Set the volume for both speakers to 7.
OUT 548, 34
OUT 549, 119

'Produce a sound that becomes increasingly lower.

FOR Length = 0 TO 100
FOR Sample = 0 TO Length
WAIT 556, 128, 128
OUT 556, 16
WAIT 556, 128, 128
OUT 556, 0
NEXT Sample

FOR Sample = 0 TO Length
WAIT 556, 128, 128
OUT 556, 16
WAIT 556, 128, 128
OUT 556, 255
NEXT Sample
NEXT Length
Sls tack shop signsugars legacy stables.

If you click on the link below you will find some QBasic books we have selected from amazon.com
Recommended QBasic Books

QBasic For All!
Copyright 1999 - 2002. All rights reserved
Anastasios Yalanopoulos

By Allison Parrish

In this tutorial, I'm going to take you through Paolo Pedercini'sp5.play library. This is a veryopinionated introduction, and it leaves out a lot of the functionality thatmakes p5.play interesting! Be sure to consult the officialexamples and (referencedocumentation)[http://p5play.molleindustria.org/docs/index.html] to get a senseof everything that the library can do.

The p5.play library provides a number of helpful objects and functions formaking games and other interactive applications. The objects and functions itintroduces are incorporated into p5.js just as though they were pre-programmedin the library.

Installation

Download the libraryhere. Unzip thearchive. You'll find a directory in the archive called lib; copy thep5.play.js file from that directory into your own sketch's librariesdirectory. Make sure to add the necessary </code> tag to your sketch's<code>index.html</code> file as well. (More information here about installing externallibraries when using the p5.js editor.)</p><h2>Sprites</h2><p>A 'sprite' is an object in a game (or other interactive application) that knowsits own size and position on the screen. Sprite objects typically expose aninterface that allows the programmer to change the sprite's position,trajectory and appearance, and to allow the programmer to easily ask questionsabout the sprite, such as if it intersects a particular position (or anothersprite).</p><h3>A single sprite</h3><p>Creating a sprite in p5.play is accomplished using the <code>createSprite()</code>function. This function returns a sprite object, which itself has a number ofattributes and methods that allow us to query and change properties of thesprite.</p><p>Here's a simple example that creates a single sprite:</p><p>The <code>createSprite()</code> function takes four parameters: the position of thesprite, and its width and height. The <code>.shapeColor</code> attribute sets the color ofthe rectangle that represents the sprite. In order for p5.play to display thesprite, we need to add the <code>drawSprites()</code> function to the end of <code>draw()</code>.</p><p>Every sprite has a <code>position</code> attribute and a <code>velocity</code> attribute. Both ofthose attributes have <code>x</code> and <code>y</code> attributes, which you can set to control theposition of the sprite and its velocity (in both dimensions). The p5.playlibrary takes care of updating the position according to the velocity foryou—you don't have to do any of the math. In the example above, thesprite is constantly moving downwards, unless you click the mouse, in whichcase the sprite is instantly moved to the mouse position.</p><h3>Sprites on the move</h3><p>As mentioned above, you can set the sprite's velocity directly with<code>.velocity.x</code> and <code>.velocity.y</code>. You can also call the sprite's <code>setSpeed()</code>attribute to tell the sprite to move in a particular direction at a particularrate. In this example, use the arrow keys to control the sprite:</p><div><span>► run sketch</span><span>◼ stop sketch</span></div><p>(The <code>key</code> variable in p5.js only works for alphanumeric characters. In orderto detect the arrow keys, we need to use thekeyCode variable.)</p><p>Adding gravity to your sketch is as easy as adding a constant downward force onevery frame (using the <code>.setSpeed()</code> method). Here's an example that causes asprite to be drawn to the screen, which moves downward on every frame and thenbounces when it reaches the bottom:</p>

How To Use Play In Background Function
► run sketch◼ stop sketch

Following the mouse

There are a number of ways to make a sprite follow the mouse. The first is toset the position directly:

► run sketch◼ stop sketch

You can also add a bit of lag to the sprite's movement by setting the X and Yvelocity to the difference between the sprite's position and the mouse'sposition:

► run sketch◼ stop sketch

Finally, you can use the .attractionPoint() method to set a force that pushesthe sprite in the direction of the mouse's position:

► run sketch◼ stop sketch

In this example, we also set the object's .maxSpeed attribute (which controlshow fast a sprite can move, regardless of the forces operating on it), its.friction attribute (which is a multiplier that slowly reduces the velocityof the object on each frame), and the .rotateToDirection attribute (which,when set to true, causes the object to rotate to the direction it's moving).

Examples follow, more narrative notes TK!

Mouse events

Sprites in the p5.play framework come with a built-in mechanism for detectingwhether or not the user is interacting with the sprite using the mouse.There are two ways to check for mouse interaction: callbacks or booleanattributes.

There are four attributes of a sprite object that you can assign functions toin order to define the sprite's behavior in relation to the user's mousemovement. The following example illustrates all four:

► run sketch◼ stop sketch

The four attributes are:

  • onMouseOver (when the mouse cursor moves over the object)
  • onMouseOut (when the mouse cursor leaves the object)
  • onMousePressed (when the user presses the mouse button, and the mousecursor is over the object)
  • onMouseReleased (when the user releases the mouse button, after anonMousePressed event)

The function that you assign to these attributes will be executed whenever thespecified event occurs. Inside the function, the expression this refers tothe object that the interaction happened to. (This is helpful for writingevent handlers that can be applied to more than one object; see below.)

Every sprite object also has a mouseIsOver attribute, which has a booleanvalue: true if the mouse is currently over the object, and false otherwise.In the following example, the two sprites respond when the mouse is over them.(For the second sprite, the reaction behavior only happens if the mouse buttonis pressed as well.)

► run sketch◼ stop sketch

Note also in this example the use of the .rotation attribute, which sets thesprite's current rotation (in degrees).

Multiple sprites

You can call the createSprite() function as many times as you want to! Thep5.play framework keeps track of all the sprites you've added behind the scenes(so you don't need to create your own data structure to store them). In thefollowing example, I've written some code in mousePressed() that creates anew sprite whenever the user clicks the mouse:

How To Use Play In Background Function Powerpoint

How To Use Play In Background Function
Example:

ON PLAY(3) GOSUB 1
PLAY ON4
CLS
DO
PLAY 'CDEFGAB'
LOOP
END

1 PRINT '*';
RETURN

PLAY

Use the PLAY statement to play music.
Here are the commands for the PLAY statement:

C, D, E, F, G, A and B are the notes.

Ooctave = Set the octave.
< = Down one octave.
> = Up one octave
Nnote = Play a note (range: 0-84, 0 = pause.)

Llength = Set the length of a note (range: 1-64, 1 = A whole note.)
Tnumber of quarter notes per minute (range: 32-255.)

ML = Play the full length set by L (legato.)
MN = Play 7/8 of the length set by L (normal.)
MS = Play 3/4 of the length set by L (staccato.)

Pnumber of quarter notes, range: 1-64.

MB = Play music in background, this will let the computer play
music while the program continues with other things.
MF = Play music in foreground, the program will be paused
until the music is done playing.

Example 1:

PLAY 'CDEFGAB'

Example 2:

PLAY 'L16 ML CDEFGAB'

Use the SOUND statement to make sounds.
The frequency can range from 37 to 32767
and the duration from 0 to 65535.
This how SOUND is used:
SOUND frequency, duration

Example:

SOUND 37, 1

Using the Microphone:

Use OUT to tell the soundcard to return one
sample of input from the microphone like this:
OUT base address + 12, 32

To read the sample returned use INP like this:
INP base address + 10

The volume for the microphone is set like this:
OUT base address + 4, 10
OUT base address + 5, volume
The range for the volume is 0 to 7.

To get the volume for the microphone, use INP like this:
OUT base address + 4, 10
INP base address + 5

Base address + number refers to the address
of an I/O port which is the base address plus number.

Example:

DEFINT A-Z

'Set the volume for the microphone.
OUT 548, 10
OUT 549, 7

x = 0
SCREEN 12: CLS
PSET (0, 128), 2
DO
IF x = 639 THEN
x = 0
CLS
PSET (0, 128), 2
ELSE
'Tell soundcard to return one sample from the microphone.
OUT 556, 32
LINE -(x, INP(554)), 2
x = x + 1
END IF
LOOP

Using the Soundcard to Produce Sound:

Use OUT to tell the soundcard that a sample
has to be sent to the speakers like this:
OUT base address + 12, 16

Use OUT base address + 12, sample to
send one sample to the speakers.

On computers which run above a certain speed it is possible
that new instructions are sent while producing sound while the
soundcard is still processing earlier instructions.
Use WAIT base address + 12, 128, 128 to wait until
the soundcard is ready for new instructions.

Before producing sound, the soundcard has to be reset like this:
OUT base address + 6, 1
OUT base address + 6, 0

The volume for both speakers is set separatly but has
to be sent as one value and is returned as one value.
The range for the volume is 0 to 15.
The value that has to be sent to set the volume is calculated like this:
volume = (left speaker volume * 16) + right speaker volume

This is how the volume for both speakers is set:
OUT base address + 4, 34
OUT base address + 5, volume

Developmentwarrior cats the games. To get the volume for both speakers, use INP like this:
OUT base address + 4, 36
INP base address + 5

The value for the volume that is returned is converted to two
separate volumes for both speakers like this:
left speaker volume = volume 16
right speaker volume = volume - (left speaker volume * 16)

Example:

Help and contribute learning. 'Reset the soundcard.
OUT 550, 1
OUT 550, 0

'Set the volume for both speakers to 7.
OUT 548, 34
OUT 549, 119

'Produce a sound that becomes increasingly lower.

FOR Length = 0 TO 100
FOR Sample = 0 TO Length
WAIT 556, 128, 128
OUT 556, 16
WAIT 556, 128, 128
OUT 556, 0
NEXT Sample

FOR Sample = 0 TO Length
WAIT 556, 128, 128
OUT 556, 16
WAIT 556, 128, 128
OUT 556, 255
NEXT Sample
NEXT Length
Sls tack shop signsugars legacy stables.

If you click on the link below you will find some QBasic books we have selected from amazon.com
Recommended QBasic Books

QBasic For All!
Copyright 1999 - 2002. All rights reserved
Anastasios Yalanopoulos

By Allison Parrish

In this tutorial, I'm going to take you through Paolo Pedercini'sp5.play library. This is a veryopinionated introduction, and it leaves out a lot of the functionality thatmakes p5.play interesting! Be sure to consult the officialexamples and (referencedocumentation)[http://p5play.molleindustria.org/docs/index.html] to get a senseof everything that the library can do.

The p5.play library provides a number of helpful objects and functions formaking games and other interactive applications. The objects and functions itintroduces are incorporated into p5.js just as though they were pre-programmedin the library.

Installation

Download the libraryhere. Unzip thearchive. You'll find a directory in the archive called lib; copy thep5.play.js file from that directory into your own sketch's librariesdirectory. Make sure to add the necessary </code> tag to your sketch's<code>index.html</code> file as well. (More information here about installing externallibraries when using the p5.js editor.)</p><h2>Sprites</h2><p>A 'sprite' is an object in a game (or other interactive application) that knowsits own size and position on the screen. Sprite objects typically expose aninterface that allows the programmer to change the sprite's position,trajectory and appearance, and to allow the programmer to easily ask questionsabout the sprite, such as if it intersects a particular position (or anothersprite).</p><h3>A single sprite</h3><p>Creating a sprite in p5.play is accomplished using the <code>createSprite()</code>function. This function returns a sprite object, which itself has a number ofattributes and methods that allow us to query and change properties of thesprite.</p><p>Here's a simple example that creates a single sprite:</p><p>The <code>createSprite()</code> function takes four parameters: the position of thesprite, and its width and height. The <code>.shapeColor</code> attribute sets the color ofthe rectangle that represents the sprite. In order for p5.play to display thesprite, we need to add the <code>drawSprites()</code> function to the end of <code>draw()</code>.</p><p>Every sprite has a <code>position</code> attribute and a <code>velocity</code> attribute. Both ofthose attributes have <code>x</code> and <code>y</code> attributes, which you can set to control theposition of the sprite and its velocity (in both dimensions). The p5.playlibrary takes care of updating the position according to the velocity foryou—you don't have to do any of the math. In the example above, thesprite is constantly moving downwards, unless you click the mouse, in whichcase the sprite is instantly moved to the mouse position.</p><h3>Sprites on the move</h3><p>As mentioned above, you can set the sprite's velocity directly with<code>.velocity.x</code> and <code>.velocity.y</code>. You can also call the sprite's <code>setSpeed()</code>attribute to tell the sprite to move in a particular direction at a particularrate. In this example, use the arrow keys to control the sprite:</p><div><span>► run sketch</span><span>◼ stop sketch</span></div><p>(The <code>key</code> variable in p5.js only works for alphanumeric characters. In orderto detect the arrow keys, we need to use thekeyCode variable.)</p><p>Adding gravity to your sketch is as easy as adding a constant downward force onevery frame (using the <code>.setSpeed()</code> method). Here's an example that causes asprite to be drawn to the screen, which moves downward on every frame and thenbounces when it reaches the bottom:</p><img src='https://cdn-stack.compsmag.com/wp-content/uploads/2021/01/1610705115_538_How-To-Play-YouTube-in-Background-on-iPhone-January-2021.png' alt='How To Use Play In Background Function' title='How To Use Play In Background Function'><div><span>► run sketch</span><span>◼ stop sketch</span></div><h3>Following the mouse</h3><p>There are a number of ways to make a sprite follow the mouse. The first is toset the position directly:</p><div><span>► run sketch</span><span>◼ stop sketch</span></div><p>You can also add a bit of lag to the sprite's movement by setting the X and Yvelocity to the difference between the sprite's position and the mouse'sposition:</p><div><span>► run sketch</span><span>◼ stop sketch</span></div><p>Finally, you can use the <code>.attractionPoint()</code> method to set a force that pushesthe sprite in the direction of the mouse's position:</p><div><span>► run sketch</span><span>◼ stop sketch</span></div><p>In this example, we also set the object's <code>.maxSpeed</code> attribute (which controlshow fast a sprite can move, regardless of the forces operating on it), its<code>.friction</code> attribute (which is a multiplier that slowly reduces the velocityof the object on each frame), and the <code>.rotateToDirection</code> attribute (which,when set to <code>true</code>, causes the object to rotate to the direction it's moving).</p><p>Examples follow, more narrative notes TK!</p><h3>Mouse events</h3><p>Sprites in the p5.play framework come with a built-in mechanism for detectingwhether or not the user is interacting with the sprite using the mouse.There are two ways to check for mouse interaction: callbacks or booleanattributes.</p><p>There are four attributes of a sprite object that you can assign functions toin order to define the sprite's behavior in relation to the user's mousemovement. The following example illustrates all four:</p><div><span>► run sketch</span><span>◼ stop sketch</span></div><p>The four attributes are:</p><ul><li><code>onMouseOver</code> (when the mouse cursor moves over the object)</li><li><code>onMouseOut</code> (when the mouse cursor leaves the object)</li><li><code>onMousePressed</code> (when the user presses the mouse button, <em>and</em> the mousecursor is over the object)</li><li><code>onMouseReleased</code> (when the user releases the mouse button, after an<code>onMousePressed</code> event)</li></ul><p>The function that you assign to these attributes will be executed whenever thespecified event occurs. Inside the function, the expression <code>this</code> refers tothe <em>object that the interaction happened to</em>. (This is helpful for writingevent handlers that can be applied to more than one object; see below.)</p><p>Every sprite object also has a <code>mouseIsOver</code> attribute, which has a booleanvalue: <code>true</code> if the mouse is currently over the object, and <code>false</code> otherwise.In the following example, the two sprites respond when the mouse is over them.(For the second sprite, the reaction behavior only happens if the mouse buttonis pressed as well.)</p><div><span>► run sketch</span><span>◼ stop sketch</span></div><p>Note also in this example the use of the <code>.rotation</code> attribute, which sets thesprite's current rotation (in degrees).</p><h3>Multiple sprites</h3><p>You can call the <code>createSprite()</code> function as many times as you want to! Thep5.play framework keeps track of all the sprites you've added behind the scenes(so you don't need to create your own data structure to store them). In thefollowing example, I've written some code in <code>mousePressed()</code> that creates anew sprite whenever the user clicks the mouse:</p><h3 id='how-to-use-play-in-background-function-powerpoint'>How To Use Play In Background Function Powerpoint</h3><img src='https://upload.wikimedia.org/wikipedia/en/5/57/IOS_14_Homescreen.png' alt='How To Use Play In Background Function' title='How To Use Play In Background Function'><div><span>► run sketch</span><span>◼ stop sketch</span></div><p>Note here the use of the <code>.life</code> attribute, which is the maximum number offrames that the sprite will 'live' before it's automatically deleted by thep5.play framework.</p><h3 id='how-to-use-play-in-background-function-excel'>How To Use Play In Background Function Excel</h3><p>If you want to apply changes to the sprites after they're created, other thanthe changes that the p5.play framework performs on its own, you'll needto iterate over every sprite in the <code>draw()</code> method. The framework supplies abuilt-in array called <code>allSprites</code> which contains every active sprite in thesketch. In the following example, we use the <code>allSprites</code> variable to apply'gravity' (i.e., a constant downward force) to each sprite added to the scenein <code>mousePressed()</code>. Another <code>if</code> statement checks to see if the sprite hasextended beyond the height of the sketch, and causes it to 'bounce' if so.Still another <code>if</code> statement removes any sprites that have exceeded theboundary of the sketch in the X dimension.</p><div><span>► run sketch</span><span>◼ stop sketch</span></div><p>Examples only from this point forward—more notes TK!</p><h3>Events on multiple sprites</h3><div><span>► run sketch</span><span>◼ stop sketch</span></div><ul><li>every sprite shares the same <code>removeAndScore</code> function—the <code>this</code> keywordkeeps everything straight</li></ul><h3>Sprite groups</h3><div><span>► run sketch</span><span>◼ stop sketch</span></div><ul><li><code>Group()</code></li><li>allows you to 'categorize' sprites and give them different behaviors.</li></ul><h2>Collisions</h2><div><span>► run sketch</span><span>◼ stop sketch</span></div><ul><li>the <code>.overlap()</code> method returns true if one sprite overlaps another.</li></ul><div><span>► run sketch</span><span>◼ stop sketch</span></div><ul><li><code>.collide()</code></li></ul><div><span>► run sketch</span><span>◼ stop sketch</span></div><ul><li><code>.displace()</code></li></ul><h3 id='how-to-use-function-lock'>How To Use Function Lock</h3><h3>Group collisions</h3><div><span>► run sketch</span><span>◼ stop sketch</span></div><h3>Collision callbacks</h3><div><span>► run sketch</span><span>◼ stop sketch</span></div><h2>Images and animations</h2><div><span>► run sketch</span><span>◼ stop sketch</span></div><h3>Animations</h3><p>(example animation below from the p5.play examples)</p><h3 id='how-to-use-play-in-background-functional'>How To Use Play In Background Functional</h3><div><span>► run sketch</span><span>◼ stop sketch</span></div><br><br><br><br>

broken image