Link to home
Start Free TrialLog in
Avatar of mathew_s
mathew_s

asked on

Silverlight How to Set Volume of Background Music after video plays

Silverlight 5

Got an issue where I am playing background music for an application. Once a user navigates from the main page to another page, a video plays and the background music volume is set lower. I then have an event once that video ends but not sure how to reference the background music from the main page from this particular view to make it work the way I want.

Page with the video that plays looks something like this. I want to set the background music back to normal level. I know the code to use, just need to figure out how to reference the method from the main page.
namespace GG.Views
{ 
    public partial class MyPage2 : Page
    {

        public AttackStrategy()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {           
            ContentText.Text = "This page blah blah";
        }

        private void media_MediaEnded(object sender, RoutedEventArgs e)
        {
            //need to do something here.
        }


    }
}

Open in new window


Main Page code, need to call this method FadeInMusic
namespace GG
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            PlayMusic();
         }
        //blah blah more code here...
        public void FadeInMusic()
        {
            _music.Volume = 0.5;
        }

Open in new window



I tried the obvious to create an instance of the main page in the view and call the method but it just plays the music again so I now have 2 instances of the music playing. how to fix this?

        private void media_MediaEnded(object sender, RoutedEventArgs e)
        {
            MainPage test = new MainPage();
            test.FadeInMusic();
        }

Open in new window

Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

how do you lower the volume, simply invert it
Avatar of mathew_s
mathew_s

ASKER

Yes I know how to set the volume back to normal level. Question is how to call the method from the view page without creating 2 instances of the music playing which currently is what happens. If I create a new instance of mainpage it will play the music again so I have the music playing twice in the background. How to get around this?
ASKER CERTIFIED SOLUTION
Avatar of mathew_s
mathew_s

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Solved it myself.