Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9207009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:17:51+00:00 2026-06-18T00:17:51+00:00

I have the following code in Draw() in Game1. However, the Music only plays

  • 0

I have the following code in Draw() in Game1. However, the Music only plays when I’m pressing the close button for the program. Where should I be putting MediaPlayer.Play() if not there? normS, fastS, slowS, and playing are all Song types. If you need me to clear anything up, just ask.

        if (stateS == "normal")
        {
            if (!MediaPlayer.Equals(playing, normS))
            {
                playing = normS;
            }

            spriteBatch.Draw(norm, pos, Color.White);
        }
        else if (stateS == "fast")
        {
            if (!MediaPlayer.Equals(playing, fastS))
            {
                playing = fastS;
            }
            spriteBatch.Draw(fast, pos, Color.White);
        }
        else if (stateS == "slow")
        {
            if (!MediaPlayer.Equals(playing, slowS))
            {
                playing = slowS;
            }
            spriteBatch.Draw(slow, pos, Color.White);
        }
        MediaPlayer.Play(playing);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:17:52+00:00Added an answer on June 18, 2026 at 12:17 am

    Is there a particular reason why you need to have the songs play out of the Draw method? Draw should be reserved for drawing things.

    Like user1306322 said in the comment above, I would recommend moving the

    MediaPlayer.Play(playing); 
    

    into the Update method, and wrap it in a conditional (so you dont just keep playing a new song every update, which I think is what is happening for you now since clicking and holding the Close Window x stops the updates. You could try this by dragging the window around as well):

    if (!MediaPlayer.IsPlaying)
    {
        MediaPlayer.Play(playing);
    }
    

    If necessary, you can leave the rest of the code in Draw, but most likely this whole thing should go in Update.

    edit I just realised you may not have a conditional on this because you want to be able to change the song at any time. In that case, you should set a variable to hold your “Last Song”, so you can compare it in your conditional like this:

    if (MediaPlayer.IsPlaying == false || playing != lastPlaying)
    {
        MediaPlayer.Play(playing);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which should simply draw a green triangle to the
I have the following code to draw text centered vertically (and horizontally) in a
I have the following code for writing draw calls to a back buffer canvas,
I have the following code in my Rails application's routes file: MyApp::Application.routes.draw do constraints
I have the following code to draw inner shadows on my UIView drawRect: //add
I have the following code to draw a square outline with the following code.
I have the following code which is supposed to draw a stroked and filled
I have the following code in my program for a blackjack game: Player *p;
I have following code. But AddGameComponent doesn't draw. protected override void Initialize() { //
I have following code to draw my logistic distribution: x=seq(-2000,2000,length=1000) dat <- data.frame(x=x) dat$value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.