The createSprite function takes four parameters: the position of the sprite, and its width and height. The.shapeColor attribute sets the color of the rectangle that represents the sprite. In order for p5.play to display the sprite, we need to add the drawSprites function to the end of draw. Every sprite has a position attribute and a velocity attribute. In this video, you're going to learn how to play your computer audio to everyone. This is like playing a track in class (everyone hears the same thing).Get Z. The background image will be positioned at 0% on the horizontal axis and 0% on the vertical axis, which means the top left corner of the element. Hello world background-position: bottom right.
To use the Play Store app, you'll need to turn background data on for your device. This means apps may download data for future reference or provide you with notifications even when you're not using the app. Settings are different on each version of Android. Check which version of Android you have. On Android 7.0 or higher. You can play a single track in the background on both an Android phone and an iPhone — but it’s a bit fiddly. And I was unable to play more than a single song in a playlist in either OS.
Here is the code for the audio element that we will be controlling.
First we will use HTML to create the play button.We will make two CSS classes, play and pause.
CODE FOR CLASSES AND BUTTON
To make our play button function, we write onclick=“playAudio” inside the button’s opening tag. This means the playAudio function is called whenever pButton is clicked. The function toggles between the .play and .pause classes and plays and pauses the audio.
The playAudio function checks if the audio is paused. If the audio is paused we call the audio element’s play function. We clear pButton’s classes and add the pause class.If the audio is playing we pause it and change pButton’s class to play.
That is all the code you need to make a play button that targets the audio element.
Functions like play and pause are part of the HTMLMediaElement’s interface. If you are interested the API is here.
Before we can start tracking the progress of the audio, we should modify our HTML. Instead of just having a play button, we will create an audio player. We will nest the button, a timeline, and a playhead inside of a div whose id will be audioplayer.
Here is the HTML and CSS. You should also add the float:left property to the play button.
The audio player should look something like this
There are two ways that we will allow users to change the track position.
The first method is accomplished by listening for clicks on the timeline, calculating the click’s position as a percent of the timeline’s width, and updating the playhead and track positions.
The code above adds an event listener to the timeline. If the timeline is clicked, this function fires which moves the playhead to the click position and updates the track’s current time.
The moveplayhead function works by changing the playhead’s left margin. The left margin controls the space between the left side of the timeline and the playhead. To calculate the correct left margin value, the x-coordinate of the click event is subtracted by the timeline’s left offset. The left offset is calculated with
The conditionals are necessary if the you want to support playhead dragging. If you don’t, just set the playhead’s left margin to newMarginLeft, as any click will be inside the timeline.
The codepen below puts everything together.
See the Pen HTML5 Audio Player by Alex Katz (@katzkode) on CodePen.
If you are interested in using multiple audio players on the same page, you can check out my code here – Multiple HTML5 Audio Players.
Music, Sounds, ON PLAY and Using the Soundcard
This tutorial is about statements used to play music, create sounds
and the ON PLAY statement.
|ON PLAY... GOSUB|
|Using the Microphone|
|Using the Soundcard to Produce Sound|
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.
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.
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
|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.
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
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)
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