8 Replies - 712 Views - Last Post: 27 June 2020 - 10:33 PM Rate Topic: -----

#1 albert003   User is offline

  • D.I.C Addict

Reputation: 38
  • View blog
  • Posts: 867
  • Joined: 15-December 14

Play music when game starts

Posted 12 June 2020 - 09:31 PM

Working on something special for my wife and I wanted to make the music play when the game starts without having to press a button. When she clicks on a button marked secret the original music playing stops and a new menu opens which plays the song from our wedding. Which will show random pictures of us. I know how to do everything except have the music start when the 'start' button is pressed on visual studio. Could someone give me a hint or an idea what I am doing wrong?

This is the program so far...

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Media; // plays music

namespace Lovemessage
{
    public partial class Form1 : Form
    {
        gameScreen ingamescreen = new gameScreen();
        public Form1()
        {
            InitializeComponent();
            SoundPlayer splayer = new SoundPlayer(@"C:\users\albert\Desktop\Johnlegend all of you.mp3");
            splayer.Play();
        }

        private void startGame(object sender, EventArgs e)
        {
            ingamescreen.Show();
        }
    }
}

This post has been edited by albert003: 12 June 2020 - 09:50 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Play music when game starts

#2 albert003   User is offline

  • D.I.C Addict

Reputation: 38
  • View blog
  • Posts: 867
  • Joined: 15-December 14

Re: Play music when game starts

Posted 13 June 2020 - 01:40 AM

Disregard I figured it out on my own after a few dozen cups of coffee and pop.

This is how I solved it.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Media; // plays music
using WMPLib;//this uses windows media player

namespace Lovemessage
{
    public partial class Form1 : Form
    {
        WindowsMediaPlayer player = new WindowsMediaPlayer();
        gameScreen ingamescreen = new gameScreen();
        public Form1()
        {
            InitializeComponent();
            player.URL = "John Legend all of me.mp3";
        }
        private void startGame(object sender, EventArgs e)
        {
            ingamescreen.Show();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            player.controls.play();
        }

        private void bindingSource1_CurrentChanged(object sender, EventArgs e)
        {

        }
    }
}

Was This Post Helpful? 0
  • +
  • -

#3 spiplc   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 4
  • Joined: 17-June 20

Re: Play music when game starts

Posted 19 June 2020 - 05:49 PM

Sorry late the first code should work but i believe it .wav file only
Was This Post Helpful? 0
  • +
  • -

#4 Radius Nightly   User is offline

  • D.I.C Regular

Reputation: 57
  • View blog
  • Posts: 365
  • Joined: 07-May 15

Re: Play music when game starts

Posted 20 June 2020 - 12:16 PM

Remembering when i was making a gift for someones birthday. I will put it here, so it may give someone an idea or help your idea.

I wanted to make a real mysteries in real life, hiding multiple objects around the house, making puzzles that she can seek, find, explore, getting connections, along side with in application puzzles, but since i had very limited time, i cut off most of my ideas, making overall shorter version.

Here is a download: https://drive.google...iew?usp=sharing


I made two "AI" personalities who talk, but they are the same AI, one is called "Echo", another one is called "Corrupted Echo", the point was, when "Echo" gets come corrupted speak, it thinks its nothing more then a corrupted code, in other hand "Corrupted Echo" thinks that "Echo" is a that bug in the code, referring to her as an insect and trying to fight the bug.
In the end, "Corrupted Echo" managed to remove "Echo", revealing the final part of a gift. She was all alone in that time, with plenty of time and under CCTV, so it was later on funny to watch for me.


This is the results:

1. Echo ask her to identify herself, solution is "Caknuta", since C is a special character, "aknuta" in the text is what Echo will seek. If she identify multiple times wrong, Echo will give some chances, but in the end, Echo will refuse to talk to the stranger, shutting down application. In other hand Echo will explain that she is a gift, about corruptions, and Corrupted Echo will start playing around.

2. The UNKNOWN puzzle. Solution is in from of you, the keyboard, as in example, under number 6, there is Y, H and N. Eg. under number 1 is Q, A and Z. According to that, result for the UNKNOWN is 7686926. Its later used for the final message.

3. A gift box, a metal box, is actually a safe metal box inside a book, that was placed in the corner of the room with other books. When whe found it, she couldnt open the safe box, because it require the key, but she got on the first page a solution, the message was printed on the paper, horizontally mirrored, with some modifications, so it cannot be read backwards, putting paper inverted on some bright light also was not working, since text was too bright already, with some holes, and one character almost missing. But when you step in front of the mirror, you can read it really clear. She took a phone, took a picture and flip it horizontally, revealing the message: "Dragon is a magical and majestic creature of knowledge, respect and honor." For solution, Echo seek words like magical, majestic, knowledge, respect and honor in order to accept.

4. Keys to unlock the metal safe box inside the book i already put in her handbag while she was on bathroom. Searching for the keys trough all your belongings was really funny. At the same time Echo started playing happy birthday song on internal "beep-beep" speaker, then fixing it and playing normally.

5. Corrupted Echo used his "insects fumigation" to fix the bug, removing Echo, asking for the code on the board that i previously already wrote. Solution is "C12". Then he reveal encrypted messages. Eg. X52 Y81 Y42... X represent big latter, Y represents lowercase latter, Z represents a number. Two numbers define row and column, if you take a look at keyboard as a table, its easy. Eg. X22 is big later S. Y82 is lowercase letter K. Z10 is number 10. After decoding, she gets multiple messages, eg. "sElf-Love iS thE souRce of All ouR othEr loves" and if you read only big letters, its "ELSE RARE". She used Office Excel to find and replace all codes with corresponding letters, because there is multiple messages.

At this point, CACHE file are created, and each time you launch the application, all you will see is codes. Delete CACHE file to restart the program. In the end whe was happy, and she wanted it more, sine she like to solve puzzles and that kind of stuff.

In the echo folder you got all audio files, file echo.zap is a text file of subtitles.
There is a download link, you can check it out and see, maybe some other unique idea hit you.
Was This Post Helpful? 1
  • +
  • -

#5 albert003   User is offline

  • D.I.C Addict

Reputation: 38
  • View blog
  • Posts: 867
  • Joined: 15-December 14

Re: Play music when game starts

Posted 22 June 2020 - 08:39 AM

spiplc
I honestly couldn't get it to work in my initial post. I couldn't figure out why so after working on it a little more I got it to work and made a post #2.

Radius Nightly
Love the game idea and ran it, it looks so awesome!. I'm still a noob so what you created is way beyond my abilities.

I do have a few questions for you or anyone else that maybe able to answer them.

1. I can't get the song to play continuously even though its suppose to play over and over again. What am I doing wrong?
2. I wanted to add a feature if my wife closed the game screen and go back to the main menu it will play the song again from the beginning. Ive tried everything on both questions and I ran out of ideas.
Was This Post Helpful? 0
  • +
  • -

#6 Radius Nightly   User is offline

  • D.I.C Regular

Reputation: 57
  • View blog
  • Posts: 365
  • Joined: 07-May 15

Re: Play music when game starts

Posted 22 June 2020 - 07:56 PM

My project was actually easy, lots of audio files and text with each character typing delay to get the illusion effect where text match voice, and what happening when user pick what.

I see you loaded the media and play it, but i dont see any kind of loop option, any looping command? Im not doing C#, but there must be some kind of loop or repeat when music finishes, to play again. Since you are using Lib, there must be some easy kind of function that you can put and say, play it in a loop. There should be some Stop, Play, Pause, Loop, Shuffle options i believe.

Using WMP is not good option, because in order to play it on another computer, it may fail, because it requires OS to have WMP and WMP Codecs, like Windows Feature Pack OOB and Feature Pack from Windows Update, that can be missing or disabled together with WMP itself.
Its best to stick with native system media, such as wav, maybe ogg, possibly mpeg2, because it will always work as is, without unnecessary third party players, their codecs and similar requirements. Avoid unnecessary headache fighting unnecessary stuff, keep it plain simple. Later on you can play and experiment with WMP or other things to get them know better.

This post has been edited by Radius Nightly: 22 June 2020 - 07:58 PM

Was This Post Helpful? 0
  • +
  • -

#7 albert003   User is offline

  • D.I.C Addict

Reputation: 38
  • View blog
  • Posts: 867
  • Joined: 15-December 14

Re: Play music when game starts

Posted 23 June 2020 - 10:58 AM

You see back when I started learning python I wanted to create something similar to what you created using the 80's movie war games as a example. But I just couldn't figure it out because it was both a gui and a video game at the same time and python won't let you do both (As far as I can tell). Now that I am learning C# using visual studio and seeing what you created for your wife I see it is possible to do it.

My plan was to have her favourite song play in the background on its own without having to press a button to start. I will try your suggestion and see if I can figure it out. What I wanted to do was have the initial form pop up playing her favourite song and when she pressed enter it will stop playing (Which it does but it wont repeat). Another feature I wanted to add was if she closed form 2 it will start to play that first song all over again.

Yeah your program is really really cool. I listened to the recording and wondered if you recorded them yourself and added a robotic voice to them?
Was This Post Helpful? 0
  • +
  • -

#8 Radius Nightly   User is offline

  • D.I.C Regular

Reputation: 57
  • View blog
  • Posts: 365
  • Joined: 07-May 15

Re: Play music when game starts

Posted 23 June 2020 - 04:22 PM

Not my wife.

Each language have its own limitations, and i like to figure out how to make something that i can not. In the end, thats what we do in programming, trying to figure out every problem to solve it, to work as we want. We like solving this kind of problems.

Audio files was created using TTS (Text To Speech) Service, there are plenty of online solutions, with different voices and speeds that offer direct audio download of what you generate. Later on i used Audacity to improve it and add couple of filters to make it sound like a robot, and not like a real person (TTS came too far in technology today and it can even replace real human talk thanks to all that corporations learning machines and listening while translating).
Was This Post Helpful? 0
  • +
  • -

#9 albert003   User is offline

  • D.I.C Addict

Reputation: 38
  • View blog
  • Posts: 867
  • Joined: 15-December 14

Re: Play music when game starts

Posted 27 June 2020 - 10:33 PM

Ill have to try it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1