Bonjour a tous,

Je débute en C# mais j'ai des connaissances en VB.NET et en C...

Je suis en train de faire une application utilisation la bibliotheque FMODex, d'ou mon choix de faire cela en C#...

J'obtient la fameuse erreur "NullReferenceException"... Mais je comprend pas pourquoi elle intervient ici...

voici mon code (ce qui est exécuté dans le pas à pas):

ah oui! j'ai oublié je travail en 64 bit mais en mettant en 32 bit cela génère la même erreur.


Initialisation :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
public static void Initialize(int NbChannel)
        {
            RESULT result;
 
            result = Factory.System_Create(ref system);
            if (EngineError != null) EngineError(result);
 
            uint version = 0;
 
            result = system.getVersion(ref version);
            if (EngineError != null) EngineError(result);
 
            if (version < VERSION.number)
            {
                throw new ApplicationException("Error! You are using an old version of FMOD " + version.ToString("X") + ". This program requires " + VERSION.number.ToString("X") + ".");
            }
 
            result = system.init(NbChannel, INITFLAGS.NORMAL, (IntPtr)null);
            if (EngineError != null) EngineError(result);
            channelCallback = new CHANNEL_CALLBACK(OnEndMusic);
 
        }

La méthode qui ne fonctionne pas (en rouge ou intervient mon erreur) :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 public static void Play()
        {
            Play(currentPath);
        }
        public static void Play(string path)
        {
            Play(path, false);
        }
        public static void Play(string path, bool paused)
        {
            bool isPlaying = false;
            RESULT result = RESULT.OK;

            if (Channel != null)
            {
                //si la musique existe
                result = Channel.isPlaying(ref isPlaying);
            }
            else
            {
                isPlaying = false;
            }

            if (EngineError != null) EngineError(result);

            if ((currentPath == path) && isPlaying)//si la musique du chemin courant est entrain detre joué
            {
                Stop();
                Play();
            }
            else if (currentPath == path)//sinon la musique du chemin courant nest pas entrain detre joué
            {
                result = system.playSound(CHANNELINDEX.FREE, music, false, ref Channel);
                if (EngineError != null) EngineError(result);
                if (Channel != null)
                    result = Channel.setCallback(channelCallback);
                if (EngineError != null) EngineError(result);
            }
            else
            {

                //si cest une nouvelle musique
                if (Channel != null)
                {
                    Channel.stop();
                    Channel = null;
                }
                if (music != null)
                {
                    result = music.release();
                    music = null;
                    if (EngineError != null) EngineError(result);
                }

                result = system.createStream(path, MODE.SOFTWARE | MODE.CREATECOMPRESSEDSAMPLE | MODE.LOOP_OFF, ref music); // probleme

                if (EngineError != null) EngineError(result);

                result = system.playSound(CHANNELINDEX.FREE, music, paused, ref Channel);
                if (EngineError != null) EngineError(result);
                if (Channel != null)
                    result = Channel.setCallback(channelCallback);
                if (EngineError != null) EngineError(result);
                currentPath = path;
                Update();

            }
        }
Bon.. jusqu'ici je n'invente rien, j'ai juste fait un copier/coller des sources que j'ai pu trouvé a plusieurs endroit sur le net...

et voici mon form qui appelle ma fonction play, et je pense que c'est a cet endroit ou il y a un problème....

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Application_Audio;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
       
       
 
        public Form1()
        {
            InitializeComponent();
            //ApplicationAudio.Initialize();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
          // ApplicationAudio.Initialize();
            Sound_Manager.SoundManager.Initialize(1);

        }



        private void button1_Click(object sender, EventArgs e)
        {

            // ApplicationAudio.PlayMusic();
            Sound_Manager.SoundManager.Play("D:\\ma_musique.mp3");

        }

        private void button2_Click(object sender, EventArgs e)
        {
            ApplicationAudio.PauseMusic();

        }

        private void button3_Click(object sender, EventArgs e)
        {
            ApplicationAudio.StopMusic();
        }

       

    }
}

voila voila... J'ai préféré posté dans le général C# car je pense que c'est une erreur qui se trouverais dans Form....

Merci d'avance !


Gab