0
0

Hi,
Are there any examples around of how to use a callback function with C#? I looked through the documentation and included C# examples, but I didn’t find anything.

I’d like to use a callback function for when the stream has ended so I can load the next song in the playlist.

-Ranthalion

  • You must to post comments
0
0

set it up:

[code:33a86mi8]channel.setCallback(FMOD.CHANNEL_CALLBACKTYPE.END, new FMOD.CHANNEL_CALLBACK(this.ev_end), 0);[/code:33a86mi8]

go to next song in playlist here:

[code:33a86mi8]FMOD.RESULT ev_end(IntPtr channelraw, FMOD.CHANNEL_CALLBACKTYPE type, int command, uint commanddata1, uint commanddata2)
{
// do work here
return FMOD.RESULT.OK;
}[/code:33a86mi8]

  • You must to post comments
0
0

Thanks,

I tried that and I get a null reference exception when I reach the end of the song. I am trying to extend the cdplayer example in C#. I have placed channel.setCallback(…) in btnPlay_Click at the very end of the function, so the channel should be initialized…

the callback function ev_end just shows a messagebox to verify the stream ended for now.. the message never pops up.

I also get an access error.
[code:1dawase2]
A first chance exception of type ‘System.AccessViolationException’ occurred in mycdapp.exe
An exception of type ‘System.AccessViolationException’ occurred in mycdapp.exe but was not handled in your code
[/code:1dawase2]

Any ideas on what could be causing this?

  • You must to post comments
0
0

Hi,
I still can’t figure out what the problem is with how I’m trying to use the callback. Here is the error I get when it crashes.
[code:1gsdorjj]
************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at FMOD.System.FMOD_System_Update(IntPtr system)
at FMOD.System.update() in c:\documents and settings\ranthalion\my documents\visual studio\projects\mycdapp\mycdapp\fmod.cs:line 1411
at mycdapp.Form1.timer1_Tick(Object sender, EventArgs e) in c:\documents and settings\ranthalion\my documents\visual studio\projects\mycdapp\mycdapp\form1.cs:line 181
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.Callback(IntPtr hWnd, Int32 msg, IntPtr idEvent, IntPtr dwTime)

************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.3600.0
Win32 Version: 2.0.40607.85 (lab26.040607-8500)

CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.40607/mscorlib.dll

mycdapp
Assembly Version: 1.0.1997.34702
Win32 Version: 1.0.1997.34702

CodeBase: file:///C:/Documents%20and%20Settings/Ranthalion/My%20Documents/Visual%20Studio/Projects/mycdapp/mycdapp/bin/Debug/mycdapp.exe

System.Windows.Forms
Assembly Version: 2.0.3600.0
Win32 Version: 2.0.40607.85 (lab26.040607-8500)

CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.3600.0__b77a5c561934e089/System.Windows.Forms.dll

System
Assembly Version: 2.0.3600.0
Win32 Version: 2.0.40607.85 (lab26.040607-8500)

CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.3600.0__b77a5c561934e089/System.dll

System.Drawing
Assembly Version: 2.0.3600.0
Win32 Version: 2.0.40607.85 (lab26.040607-8500)

CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.3600.0__b03f5f7f11d50a3a/System.Drawing.dll

System.Xml
Assembly Version: 2.0.3600.0
Win32 Version: 2.0.40607.85 (lab26.040607-8500)

CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.3600.0__b77a5c561934e089/System.Xml.dll

[/code:1gsdorjj]

It seems some object that is needed has not been instantiated, but as far as I know, everything is.

Here is my source code if it will help. Like I said, I’m just trying to enhance the cdplayer.cs example.

[code:1gsdorjj]
namespace mycdapp
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
private FMOD.System system = null;
private FMOD.Sound sound = null;
private FMOD.Sound cdsound = null;
private FMOD.Channel channel = null;
private int currentTrack = 0;
private int numTracks = 0;
private string[] drives;
private bool isTracking = false;

    /// &lt;summary&gt;
    /// Clean up any resources being used.
    /// &lt;/summary&gt;
    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {
            FMOD.RESULT result;

            if (cdsound != null)
            {
                result = cdsound.release();
                ERRCHECK(result);
            }

            if (system != null)
            {
                result = system.close();
                ERRCHECK(result);

                result = system.release();
                ERRCHECK(result);
            }

            if (components!=null)
                components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// &lt;summary&gt;
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// &lt;/summary&gt;
    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        this.btnPlay = new System.Windows.Forms.Button();
        this.btnPause = new System.Windows.Forms.Button();
        this.btnStop = new System.Windows.Forms.Button();
        this.btnPrevious = new System.Windows.Forms.Button();
        this.btnNext = new System.Windows.Forms.Button();
        this.comboBox1 = new System.Windows.Forms.ComboBox();
        this.timer1 = new System.Windows.Forms.Timer(this.components);
        this.statusStrip1 = new System.Windows.Forms.StatusStrip();
        this.statusStripPanel1 = new System.Windows.Forms.StatusStripPanel();
        this.toolStripProgressBar1 = new System.Windows.Forms.ToolStripProgressBar();
        this.leftRaftingContainer = new System.Windows.Forms.RaftingContainer();
        this.rightRaftingContainer = new System.Windows.Forms.RaftingContainer();
        this.topRaftingContainer = new System.Windows.Forms.RaftingContainer();
        this.bottomRaftingContainer = new System.Windows.Forms.RaftingContainer();
        this.label1 = new System.Windows.Forms.Label();
        this.trackBar1 = new System.Windows.Forms.TrackBar();
        this.statusStrip1.SuspendLayout();
        ((System.ComponentModel.ISupportInitialize)(this.leftRaftingContainer)).BeginInit();
        ((System.ComponentModel.ISupportInitialize)(this.rightRaftingContainer)).BeginInit();
        ((System.ComponentModel.ISupportInitialize)(this.topRaftingContainer)).BeginInit();
        ((System.ComponentModel.ISupportInitialize)(this.bottomRaftingContainer)).BeginInit();
        this.bottomRaftingContainer.SuspendLayout();
        ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
        this.SuspendLayout();

//
// btnPlay
//
this.btnPlay.Location = new System.Drawing.Point(13, 133);
this.btnPlay.Name = "btnPlay";
this.btnPlay.Size = new System.Drawing.Size(93, 87);
this.btnPlay.TabIndex = 0;
this.btnPlay.Text = "PLAY";
this.btnPlay.Click += new System.EventHandler(this.btnPlay_Click);
//
// btnPause
//
this.btnPause.Location = new System.Drawing.Point(113, 133);
this.btnPause.Name = "btnPause";
this.btnPause.Size = new System.Drawing.Size(99, 87);
this.btnPause.TabIndex = 1;
this.btnPause.Text = "PAUSE";
this.btnPause.Click += new System.EventHandler(this.btnPause_Click);
//
// btnStop
//
this.btnStop.Location = new System.Drawing.Point(219, 136);
this.btnStop.Name = "btnStop";
this.btnStop.Size = new System.Drawing.Size(88, 82);
this.btnStop.TabIndex = 2;
this.btnStop.Text = "STOP";
//
// btnPrevious
//
this.btnPrevious.Location = new System.Drawing.Point(314, 139);
this.btnPrevious.Name = "btnPrevious";
this.btnPrevious.Size = new System.Drawing.Size(93, 81);
this.btnPrevious.TabIndex = 3;
this.btnPrevious.Text = "PREVIOUS";
this.btnPrevious.Click += new System.EventHandler(this.btnPrevious_Click);
//
// btnNext
//
this.btnNext.Location = new System.Drawing.Point(428, 142);
this.btnNext.Name = "btnNext";
this.btnNext.Size = new System.Drawing.Size(90, 75);
this.btnNext.TabIndex = 4;
this.btnNext.Text = "NEXT";
this.btnNext.Click += new System.EventHandler(this.btnNext_Click);
//
// comboBox1
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(38, 57);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(242, 21);
this.comboBox1.TabIndex = 5;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// statusStrip1
//
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.statusStripPanel1,
this.toolStripProgressBar1});
this.statusStrip1.Location = new System.Drawing.Point(0, 0);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Padding = new System.Windows.Forms.Padding(0, 0, 12, 0);
this.statusStrip1.Raft = System.Windows.Forms.RaftingSides.Bottom;
this.statusStrip1.TabIndex = 0;
this.statusStrip1.Text = "statusStrip1";
//
// statusStripPanel1
//
this.statusStripPanel1.AutoSize = false;
this.statusStripPanel1.Name = "statusStripPanel1";
this.statusStripPanel1.SettingsKey = "Form1.statusStripPanel1";
this.statusStripPanel1.Size = new System.Drawing.Size(420, 16);
this.statusStripPanel1.Text = "CD Info";
//
// toolStripProgressBar1
//
this.toolStripProgressBar1.Name = "toolStripProgressBar1";
this.toolStripProgressBar1.SettingsKey = "Form1.toolStripProgressBar1";
this.toolStripProgressBar1.Size = new System.Drawing.Size(92, 15);
this.toolStripProgressBar1.Text = "toolStripProgressBar1";
//
// leftRaftingContainer
//
this.leftRaftingContainer.Dock = System.Windows.Forms.DockStyle.Left;
this.leftRaftingContainer.Name = "leftRaftingContainer";
//
// rightRaftingContainer
//
this.rightRaftingContainer.Dock = System.Windows.Forms.DockStyle.Right;
this.rightRaftingContainer.Name = "rightRaftingContainer";
//
// topRaftingContainer
//
this.topRaftingContainer.Dock = System.Windows.Forms.DockStyle.Top;
this.topRaftingContainer.Name = "topRaftingContainer";
//
// bottomRaftingContainer
//
this.bottomRaftingContainer.Controls.Add(this.statusStrip1);
this.bottomRaftingContainer.Dock = System.Windows.Forms.DockStyle.Bottom;
this.bottomRaftingContainer.Name = "bottomRaftingContainer";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(321, 25);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 14);
this.label1.TabIndex = 10;
this.label1.Text = "label1";
//
// trackBar1
//
this.trackBar1.Location = new System.Drawing.Point(303, 57);
this.trackBar1.Maximum = 100;
this.trackBar1.Name = "trackBar1";
this.trackBar1.Size = new System.Drawing.Size(162, 45);
this.trackBar1.TabIndex = 15;
this.trackBar1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.trackBar1_MouseUp);
this.trackBar1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.trackBar1_MouseDown);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(547, 264);
this.Controls.Add(this.trackBar1);
this.Controls.Add(this.label1);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.btnNext);
this.Controls.Add(this.btnPrevious);
this.Controls.Add(this.btnStop);
this.Controls.Add(this.btnPause);
this.Controls.Add(this.btnPlay);
this.Controls.Add(this.leftRaftingContainer);
this.Controls.Add(this.rightRaftingContainer);
this.Controls.Add(this.topRaftingContainer);
this.Controls.Add(this.bottomRaftingContainer);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.statusStrip1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.leftRaftingContainer)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.rightRaftingContainer)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.topRaftingContainer)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.bottomRaftingContainer)).EndInit();
this.bottomRaftingContainer.ResumeLayout(false);
this.bottomRaftingContainer.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();

    }

    #endregion

    private System.Windows.Forms.Button btnPlay;
    private System.Windows.Forms.Button btnPause;
    private System.Windows.Forms.Button btnStop;
    private System.Windows.Forms.Button btnPrevious;
    private System.Windows.Forms.Button btnNext;
    private System.Windows.Forms.ComboBox comboBox1;
    private System.Windows.Forms.Timer timer1;
    private System.Windows.Forms.StatusStrip statusStrip1;
    private System.Windows.Forms.RaftingContainer leftRaftingContainer;
    private System.Windows.Forms.RaftingContainer rightRaftingContainer;
    private System.Windows.Forms.RaftingContainer topRaftingContainer;
    private System.Windows.Forms.RaftingContainer bottomRaftingContainer;
    private System.Windows.Forms.StatusStripPanel statusStripPanel1;
    private System.Windows.Forms.ToolStripProgressBar toolStripProgressBar1;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.TrackBar trackBar1;
}

}
[/code:1gsdorjj]

[code:1gsdorjj]
namespace mycdapp
{
partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void Form1_Load(object sender, EventArgs e)
    {
        uint version = 0;
        //int numDrives = 0;
        FMOD.RESULT result;

        btnPlay.Enabled = false;
        btnPause.Enabled = false;
        btnStop.Enabled = false;
        btnNext.Enabled = false;
        btnPrevious.Enabled = false;

        result = FMOD.Factory.System_Create(ref system);
        ERRCHECK(result);

        result = system.getVersion(ref version);
        ERRCHECK(result);
        if (version &lt; FMOD.VERSION.number)
        {
            MessageBox.Show(&quot;Error! You are using an old version of FMOD &quot; + version.ToString(&quot;X&quot;) + &quot;.  This program requires &quot; + FMOD.VERSION.number.ToString(&quot;X&quot;) + &quot;.&quot;);
            Application.Exit();
        }

        result = system.init(1, FMOD.INITFLAG.NORMAL, (IntPtr)null);
        ERRCHECK(result);

        result = system.setStreamBufferSize(64 * 1024, FMOD.TIMEUNIT.RAWBYTES);
        ERRCHECK(result);

        drives = Environment.GetLogicalDrives();

        //result=system.getNumCDROMDrives(ref numDrives);
        //ERRCHECK(result);



        for (int count = 0; count &lt; drives.Length; count++)
        {
            comboBox1.Items.Add(drives[count].Remove(2, 1));
        }
    }

    private void btnPlay_Click(object sender, EventArgs e)
    {
        FMOD.RESULT result;

        result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel);
        ERRCHECK(result);

        result = channel.setCallback(FMOD.CHANNEL_CALLBACKTYPE.END, new FMOD.CHANNEL_CALLBACK(this.ev_end), 0);
        ERRCHECK(result);

        btnPlay.Enabled = false;
    }

    private void btnNext_Click(object sender, EventArgs e)
    {
        FMOD.RESULT result;

        currentTrack++;
        if (currentTrack &gt;= numTracks)
        {
            currentTrack = 0;
        }

        result = cdsound.getSubSound(currentTrack, ref sound);
        ERRCHECK(result);
        result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel);
        ERRCHECK(result);

    }

    private void btnPause_Click(object sender, EventArgs e)
    {
        FMOD.RESULT result;
        bool paused = false;

        result = channel.getPaused(ref paused);
        ERRCHECK(result);
        result = channel.setPaused(!paused);
        ERRCHECK(result);

    }

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        FMOD.RESULT result;

        string selected = drives[comboBox1.SelectedIndex].Remove(2, 1);

        result = system.createSound(selected, (FMOD.MODE.HARDWARE | FMOD.MODE._2D | FMOD.MODE.CREATESTREAM | FMOD.MODE.OPENONLY), ref cdsound);
        ERRCHECK(result);
        result = cdsound.getNumSubSounds(ref numTracks);
        ERRCHECK(result);
        result = cdsound.getSubSound(currentTrack, ref sound);
        ERRCHECK(result);

        btnPlay.Enabled = true;
        btnPause.Enabled = true;
        btnNext.Enabled = true;
        comboBox1.Enabled = false;
        btnPrevious.Enabled = true;
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        FMOD.RESULT result;
        uint ms = 0;
        uint lenms = 0;
        uint lenmscd = 0;
        bool playing = false;
        bool paused = false;
        double progress = 0;

        FMOD.TAG tag = new FMOD.TAG();
        int numtags = 0;
        int updated = 0;


        if (channel != null)
        {
            result = channel.getPaused(ref paused);
            ERRCHECK(result);
            result = channel.isPlaying(ref playing);
            ERRCHECK(result);
            result = channel.getPosition(ref ms, FMOD.TIMEUNIT.MS);
            ERRCHECK(result);
            result = sound.getLength(ref lenms, FMOD.TIMEUNIT.MS);
            ERRCHECK(result);
        }

        if (cdsound != null)
        {
            result = cdsound.getLength(ref lenmscd, FMOD.TIMEUNIT.MS);
            ERRCHECK(result);
        }

        if (sound != null)
        {
            result = sound.getNumTags(ref numtags, ref updated);
            ERRCHECK(result);
            label1.Text = updated.ToString();
        }

        if (lenms &gt; 0)
        {
            toolStripProgressBar1.Value = 50;
            progress = ((double)ms / (double)lenms * 100);
        }


        toolStripProgressBar1.Value = (int)progress;
        if (!isTracking)
            trackBar1.Value = (int)progress;

        statusStripPanel1.Text= &quot;Total CD length: &quot; + (lenmscd / 1000 / 60) + &quot;:&quot; + (lenmscd / 1000 % 60) + &quot;:&quot; + (lenmscd / 10 % 100) +
                        &quot; Track &quot; + (currentTrack + 1) + &quot;/&quot; + numTracks + &quot; : &quot; + (ms / 1000 / 60) + &quot;:&quot; + (ms / 1000 % 60) + &quot;:&quot; + (ms / 10 % 100) + &quot;/&quot; + (lenms / 1000 / 60) + &quot;:&quot; + (lenms / 1000 % 60) + &quot;:&quot; + (lenms / 10 % 100) + (paused ? &quot; Paused &quot; : playing ? &quot; Playing&quot; : &quot; Stopped&quot;);

        if (system != null)
        {
            system.update();
        }

    }

    private void ERRCHECK(FMOD.RESULT result)
    {
        if (result != FMOD.RESULT.OK)
        {
            timer1.Stop();
            MessageBox.Show(&quot;FMOD error! &quot; + result + &quot; - &quot; + FMOD.Error.String(result));
            Environment.Exit(-1);
        }
    }

    private void btnPrevious_Click(object sender, EventArgs e)
    {
        FMOD.RESULT result;

        currentTrack--;
        if (currentTrack &lt;= 0)
        {
            currentTrack = 0;
        }

        result = cdsound.getSubSound(currentTrack, ref sound);
        ERRCHECK(result);
        result = system.playSound(FMOD.CHANNELINDEX.FREE, sound, false, ref channel);
        ERRCHECK(result);

    }

    public FMOD.RESULT ev_end(IntPtr channelraw, FMOD.CHANNEL_CALLBACKTYPE type, int command, uint commanddata1, uint commanddata2)
    {
        //MessageBox.Show(&quot;End of stream&quot;);

        return FMOD.RESULT.OK;
    }

    private void trackBar1_MouseUp(object sender, MouseEventArgs e)
    {
        float seekpoint=0;
        uint destination=0;
        uint lenms=0;
        FMOD.RESULT result;

        result = sound.getLength(ref lenms, FMOD.TIMEUNIT.MS);
        ERRCHECK(result);

        seekpoint = trackBar1.Value;

        destination = (uint)((seekpoint / 100) * lenms);

        if (destination &lt; 0)
            destination = 0;
        if (destination &gt; lenms)
            destination = lenms;

        result = channel.setPosition(destination, FMOD.TIMEUNIT.MS);
        ERRCHECK(result);

        isTracking = false;
    }

    private void trackBar1_MouseDown(object sender, MouseEventArgs e)
    {
        isTracking = true;
    }
}

}
[/code:1gsdorjj]

  • You must to post comments
0
0

My VB.NET class was doing the same thing. I have got it fixed I believe. Though, the error will come up randomly, while the song is playing. I think it has to do with the Update function.

[code:376urwsv].
<DllImport("fmodex.dll", EntryPoint:="FMOD_System_Update", CharSet:=CharSet.Ansi, ExactSpelling:=False)> _
Private Shared Function UpdateSystem(ByVal system As Integer) As Result
End Function[/code:376urwsv]

My callback code is as follows:

import:
[code:376urwsv].
<DllImport("fmodex.dll", EntryPoint:="FMOD_Channel_SetCallback", CharSet:=CharSet.Ansi, ExactSpelling:=False)> _
Private Shared Function SetCallback(ByVal channel As Integer, ByVal type_ As CallBackType, ByVal callback As endStreamCallBack, ByVal command As Integer) As Result
End Function[/code:376urwsv]

Snipped class code:
[code:376urwsv].

Region " Updater "

Private Shared WithEvents tick As New Timers.Timer

Private Shared Sub [Update](ByVal sender As Object, ByVal e As system.Timers.ElapsedEventArgs) Handles tick.Elapsed
    If [system] Then
        Call UpdateSystem([system])
        Call Application.DoEvents()
    End If
End Sub

End Region

Private Delegate Sub endStreamCallBack(ByVal channel As IntPtr, ByVal type As CallBackType, ByVal command As Integer, ByVal data1 As UInt32, ByVal data2 As UInt32)
Private Shared streamCallBack As endStreamCallBack

Public Shared Sub Initialize()
Dim ref As Integer

    If Not CreateSystem([system]) = Result.FMOD_OK Then
        Call Debug.WriteLine(&quot;System creation failed&quot;, &quot;Error&quot;)
        Call Deinitalize()
        Exit Sub
    End If

    Call GetVersion([system], ref)

    If Not ref = Version Then
        Call Debug.WriteLine(&quot;Invalid FMod version&quot;, &quot;Error&quot;)
        Call Deinitalize()
        Exit Sub
    End If

    If Not InitSystem([system], 32, &amp;H0, 0) = Result.FMOD_OK Then
        Call Debug.WriteLine(&quot;Initialization failed&quot;, &quot;Error&quot;)
        Call Deinitalize()
        Exit Sub
    End If

    tick.Interval = 50

End Sub

Public Shared Sub Deinitalize()

    Call tick.Stop()

    If [sound] Then
        Call CloseSound([sound])
    End If

    If [system] Then
        Call CloseSystem([system])
        Call ReleaseSystem([system])
    End If

End Sub

Public Shared Sub Reset()

    Call tick.Stop()

    If [sound] Then
        Call CloseSound([sound])
        fileName = vbNullString
        [channel] = 0
        [sound] = 0
    End If

End Sub

Public Shared Sub Open(ByVal file As String)
    Call Reset()

    [sound] = GetStream(file)

    Call PlaySound([system], ChannelIndex.FMOD_CHANNEL_FREE, sound, 0, channel)
    streamCallBack = New endStreamCallBack(AddressOf endOfStream)
    Call SetCallback([channel], CallBackType.FMOD_CHANNEL_CALLBACKTYPE_END, streamCallBack, 0)
    Call UpdateSystem([system])
    Call tick.Start()

End Sub

Public Shared Function GetStream(ByVal file As String) As Integer
    Dim ret As Integer, nfo As CreateSoundExInfo

    nfo.cbsize = CreateSoundExInfoSize

    Call CreateStream([system], file, 0, nfo, ret)

    Return ret
End Function

[/code:376urwsv]

Edit: Works great so far, I’ve been testing it for a lil’ while now.

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.