This project has moved and is read-only. For the latest updates, please go here.

FadeInOut not working in ASPNET

Sep 19, 2013 at 8:07 AM
Hi guys,

I found a problem and cannot solve it, this code works perfectly in Windows Application, but not in Web Application, and still can't figure out why. I used source code from NAudioDemo - FadeInOutDemo, and this is the code:

private IWavePlayer wavePlayer;
private AudioFileReader file;
private FadeInOutSampleProvider fadeInOut;
private string fileName = "C:\music\intro.mp3";

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Debug.Assert(this.wavePlayer == null);
            this.wavePlayer = new WaveOutEvent();
            this.file = new AudioFileReader(fileName);
            this.fadeInOut = new FadeInOutSampleProvider(file);
            this.wavePlayer.Init(new SampleToWaveProvider(fadeInOut));
            this.wavePlayer.Play();
            timer1.Enabled = true;
        }
    }
protected void timer1_Tick(object sender, EventArgs e)
    {
        if (fadeInOut != null)
        {
            fadeInOut.BeginFadeOut(5000);
        }
        timer1.Interval = 150000;
    }
I am still not sure why does FadeOut only occurs in desktop app and not in web app, I appreciate your help.
Sep 19, 2013 at 8:09 AM
what sort of timer are you using? It it relies on windows messages (Windws.Forms.Timer) it will never tick in a web app
Sep 19, 2013 at 8:22 AM
Hi Mark,

Timer is Ajax extension and it is ticking without problem, I just got figured out what is the true problem - PageUnloadEvent is firing even if page is not unloaded, I have to figure out why is it happening, because when PageUnload event is executed fadeInOut change it's value to null, but song is still playing without problems.
Sep 19, 2013 at 8:25 AM
Also want to say fadeOut is working when I call it from PageUnload event, so it is not a problem with NAudio, there is another problem.

Best regards,
Vlad
Sep 19, 2013 at 8:58 AM
Hi Mark,

I found out that Unload event is part of the page life cycle, and it's normal that Unload event is raised after the page has been fully rendered, so I will always got fadeInOut equals null no matter what event is raised next. Do you have some aspnet example of FadeInOut?

Best regards,
Vlad