Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added multiple usage examples for audio functions #324

Open
wants to merge 3 commits into
base: usage-examples
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using SplashKitSDK;

namespace FadeMusicInNamedExample
{
public class Program
{
public static void Main()
{
// Check if audio is ready to use
if(! SplashKit.AudioReady())
SplashKit.OpenAudio();

// Load music file
SplashKit.LoadMusic("adventure", "time_for_adventure.mp3");

// Fade music in over 2 seconds
SplashKit.FadeMusicIn("adventure", 2000);

// Hold program for 10 seconds
SplashKit.Delay(10000);

// Free resources
SplashKit.FreeAllMusic();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using SplashKitSDK;
using static SplashKitSDK.SplashKit;


// Check if audio is ready to use
if(! AudioReady())
OpenAudio();

// Load music file
LoadMusic("adventure", "time_for_adventure.mp3");

// Fade music in over 2 seconds
FadeMusicIn("adventure", 2000);

// Hold program for 10 seconds
Delay(10000);

// Free resources
FreeAllMusic();

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "splashkit.h"

int main()
{
// Check if audio is ready to use
if(! audio_ready())
open_audio();

// Load music file
load_music("adventure", "time_for_adventure.mp3");

// Fade music in over 2 seconds
fade_music_in("adventure",2000);

// Hold program for 10 seconds
delay(10000);

// Free resources
free_all_music();
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from splashkit import *

# Check if audio is ready to use
if not audio_ready():
open_audio()

# Load music file
load_music("adventure", "time_for_adventure.mp3")

# Fade music in over 2 seconds
fade_music_in_named("adventure",2000)

# Hold program for 10 seconds
delay(10000)

# Free resources
free_all_music()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#### Basic Music Fade In

The following code shows examples of using [Fade Music In](/api/audio#fade-music-in) to fade the music in over 2 seconds, gradually reaching full volume.

:::note
To test this example code you can download these [**Resources**](/usage-examples/audio/fade_music_in_named/Resources.zip).
:::
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using SplashKitSDK;

namespace FadeMusicOutExample
{
public class Program
{
public static void Main()
{
// Check if audio is ready to use
if(! SplashKit.AudioReady())
SplashKit.OpenAudio();

// Load music file and start playback
Music music = SplashKit.LoadMusic("adventure", "time_for_adventure.mp3");
music.Play();


// Wait 1 second before fadeout
SplashKit.Delay(1000);

// Fade music out over 3 seconds
SplashKit.FadeMusicOut(3000);

// Hold program for 4 seconds
SplashKit.Delay(4000);

// Free resources
SplashKit.FreeAllMusic();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using SplashKitSDK;
using static SplashKitSDK.SplashKit;

// Check if audio is ready to use
if(! AudioReady())
OpenAudio();

// Load music file and start playback
LoadMusic("adventure", "time_for_adventure.mp3");
PlayMusic("adventure");

// Wait 1 second before fadeout
Delay(1000);

// Fade music out over 3 seconds
FadeMusicOut(3000);

// Hold program for 4 seconds
Delay(4000);

// Free resources
FreeAllMusic();
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "splashkit.h"

int main()
{
// Check if audio is ready to use
if(! audio_ready())
open_audio();

// Load music file and start playback
load_music("adventure", "time_for_adventure.mp3");
play_music("adventure");

// Wait 1 second before fadeout
delay(1000);

// Fade music out over 3 seconds
fade_music_out(3000);

// Hold program for 4 seconds
delay(4000);

// Free resources
free_all_music();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from splashkit import *

# Check if audio is ready to use
if not audio_ready():
open_audio()

# Load music file and start playback
load_music("adventure", "time_for_adventure.mp3")
play_music_named("adventure")

# Wait 1 second before fadeout
delay(1000)

# Fade music out over 3 seconds
fade_music_out(3000)

# Hold program for 4 seconds
delay(4000)

# Free resources
free_all_music()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#### Basic Music Fade Out

The following code shows examples of using [Fade Music Out](/api/audio#fade-music-out) to fade the music out over 3 seconds, gradually lowering the volume until the music stops.

:::note
To test this example code you can download these [**Resources**](/usage-examples/audio/fade_music_out/Resources.zip).
:::
Binary file not shown.
Binary file not shown.
28 changes: 28 additions & 0 deletions public/usage-examples/audio/load_music/load_music-1-simple-oop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using SplashKitSDK;

namespace LoadMusicExample
{
public class Program

{
public static void Main()
{
// Check if audio is ready to use
if (!SplashKit.AudioReady())
SplashKit.OpenAudio();

// Load music file
SplashKit.LoadMusic("adventure", "time_for_adventure.mp3");

// Check for successful load
if (SplashKit.HasMusic("adventure"))
SplashKit.WriteLine("Music successfully loaded. Ready for playback.");
else
SplashKit.WriteLine("Loading music failed.");

// Cleanup
SplashKit.FreeAllMusic();
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using SplashKitSDK;
using static SplashKitSDK.SplashKit;

// Check if audio is ready to use
if (!AudioReady())
OpenAudio();

// Load music file
LoadMusic("adventure", "time_for_adventure.mp3");

// Check for successful load
if (HasMusic("adventure"))
WriteLine("Music successfully loaded. Ready for playback.");
else
WriteLine("Loading music failed.");

// Cleanup
FreeAllMusic();

21 changes: 21 additions & 0 deletions public/usage-examples/audio/load_music/load_music-1-simple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "splashkit.h"

int main()
{
// Check if audio is ready to use
if(! audio_ready())
open_audio();

// Load music file
load_music("adventure", "time_for_adventure.mp3");

// Check for successful load
if (has_music("adventure"))
write_line("Music successfully loaded. Ready for playback.");
else
write_line("Loading music failed.");

// Cleanup
free_all_music();

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions public/usage-examples/audio/load_music/load_music-1-simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from splashkit import *


# Check if audio is ready to use
if not audio_ready():
open_audio()

# Load music file
load_music("adventure", "time_for_adventure.mp3")

# Check for successful load
if has_music("adventure"):
write_line("Music successfully loaded. Ready for playback.")
else:
write_line("Loading music failed.")

# Cleanup
free_all_music()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#### Basic Load Music

The following code shows examples of using [Load Music](/api/audio#load-music) to load a music file. The program will check if the music was loaded successfully or not and report in the console.

:::note
To test this example code you can download these [**Resources**](/usage-examples/audio/load_music/Resources.zip).
:::
Binary file not shown.
34 changes: 34 additions & 0 deletions public/usage-examples/audio/music_name/music_name-1-simple-oop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using SplashKitSDK;

namespace MusicNameExample
{
public class Program
{
public static void Main()
{
// Check if audio is ready to use
if(! SplashKit.AudioReady())
SplashKit.OpenAudio();

// Load music file and start playback
Music music = SplashKit.LoadMusic("adventure", "time_for_adventure.mp3");
music.Play();

// Open Window
Window window = SplashKit.OpenWindow("Music File", 600, 600);

// Main Loop
while (! SplashKit.QuitRequested())
{
SplashKit.ProcessEvents();

window.Clear(Color.White);
// Draw name of music track to screen
window.DrawText("Current Music: " + SplashKit.MusicName(music), Color.Black, 100, 300);
window.Refresh();
}
SplashKit.CloseAllWindows();
SplashKit.FreeMusic(music);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using SplashKitSDK;
using static SplashKitSDK.SplashKit;

// Check if audio is ready to use
if(! AudioReady())
OpenAudio();

// Load music file and start playback
Music music = LoadMusic("adventure", "time_for_adventure.mp3");
PlayMusic(music);

// Open Window
Window window = OpenWindow("Music File", 600, 600);

// Main Loop
while (! QuitRequested())
{
ProcessEvents();

window.Clear(Color.White);
// Draw name of music track to screen
window.DrawText("Current Music: " + MusicName(music), Color.Black, 100, 300);
window.Refresh();
}
CloseAllWindows();
FreeMusic(music);
Loading