<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Background Musik unter Window Forms]]></title><description><![CDATA[<p>Nabend allerseits,</p>
<p>ich habe mir ein GUI gebastelt und möchte, dass sobald das Programm gestartet wird, Hintergrundmusik abgespielt wird.</p>
<p>Für die Hintergrundmusik habe ich eine eigene .cpp Datei erstellt:</p>
<pre><code class="language-cpp">#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;windows.h&gt;
#include &quot;include/irrKlang.h&quot;

using namespace std;
using namespace irrklang;

#pragma comment(lib, &quot;irrKlang.lib&quot;)

void backgroundSound() {

	ISoundEngine* engine = createIrrKlangDevice();

	if(!engine) {
		return;

	}

	string sSoundFile = &quot;La Musica Notturna (Passa Calle).mp3&quot;;

	if(engine-&gt;play2D(sSoundFile.c_str()) != 0) {
		return;
	}

	while(engine-&gt;isCurrentlyPlaying(sSoundFile.c_str())) {
		Sleep(100);
	}

	engine-&gt;drop();

}
</code></pre>
<p>Jetzt weiß ich allerdings nicht, wo ich die Funktion aufrufen soll...</p>
<p>Kann mir da einer helfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/306065/background-musik-unter-window-forms</link><generator>RSS for Node</generator><lastBuildDate>Sat, 08 Aug 2026 12:25:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/306065.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 16 Jul 2012 21:04:34 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Background Musik unter Window Forms on Mon, 16 Jul 2012 21:04:34 GMT]]></title><description><![CDATA[<p>Nabend allerseits,</p>
<p>ich habe mir ein GUI gebastelt und möchte, dass sobald das Programm gestartet wird, Hintergrundmusik abgespielt wird.</p>
<p>Für die Hintergrundmusik habe ich eine eigene .cpp Datei erstellt:</p>
<pre><code class="language-cpp">#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;windows.h&gt;
#include &quot;include/irrKlang.h&quot;

using namespace std;
using namespace irrklang;

#pragma comment(lib, &quot;irrKlang.lib&quot;)

void backgroundSound() {

	ISoundEngine* engine = createIrrKlangDevice();

	if(!engine) {
		return;

	}

	string sSoundFile = &quot;La Musica Notturna (Passa Calle).mp3&quot;;

	if(engine-&gt;play2D(sSoundFile.c_str()) != 0) {
		return;
	}

	while(engine-&gt;isCurrentlyPlaying(sSoundFile.c_str())) {
		Sleep(100);
	}

	engine-&gt;drop();

}
</code></pre>
<p>Jetzt weiß ich allerdings nicht, wo ich die Funktion aufrufen soll...</p>
<p>Kann mir da einer helfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2233322</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2233322</guid><dc:creator><![CDATA[Zel2491]]></dc:creator><pubDate>Mon, 16 Jul 2012 21:04:34 GMT</pubDate></item><item><title><![CDATA[Reply to Background Musik unter Window Forms on Tue, 17 Jul 2012 00:11:47 GMT]]></title><description><![CDATA[<p>Schreib alles bis zu der while Schleife (exklusive) in eine &quot;StartBackgroundMusic&quot; Funktion, die while Schleife selbst wird zu deinem Hauptprogramm, und der Rest (engine-&gt;drop()) kommt in eine &quot;StopBackgroundMusic&quot; Funktion.</p>
<p>Den ISoundEngine-Zeiger musst du dazu natürlich irgendwo abspeichern wo die &quot;StopBackgroundMusic&quot; Funktion dann auch wieder drankommt. Einfachste Lösung: mach ne globale Variable.</p>
<p>Davon abgesehen: was hat das bitte mit &quot;Window(s) Forms&quot; zu tun?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2233347</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2233347</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Tue, 17 Jul 2012 00:11:47 GMT</pubDate></item><item><title><![CDATA[Reply to Background Musik unter Window Forms on Tue, 17 Jul 2012 11:55:38 GMT]]></title><description><![CDATA[<p>Ich hab jetzt mal n bissl ummodelliert^^</p>
<p>.h Datei</p>
<pre><code class="language-cpp">#pragma once

#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;windows.h&gt;
#include &quot;include/irrKlang.h&quot;

#pragma comment(lib, &quot;irrklang.lib&quot;)

using namespace std;
using namespace irrklang;

class HintergrundMusik {

private:
	ISoundEngine* soundEngine;
	ISound* currentSound;
	string soundFile;

public:
	HintergrundMusik();
	HintergrundMusik(string);
	~HintergrundMusik();

	void spieleSoundThread();
	bool spielt();

};
</code></pre>
<p>.cpp Datei</p>
<pre><code class="language-cpp">#include &quot;HintergrundMusik.h&quot;
#include &quot;stdafx.h&quot;
#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;windows.h&gt;
#include &quot;include/irrKlang.h&quot;

using namespace std;
using namespace irrklang;

HintergrundMusik::HintergrundMusik() {

	soundEngine = createIrrKlangDevice();
	currentSound = 0;

	if(!soundEngine) {
		exit(0);
	}

}

HintergrundMusik::HintergrundMusik(string sSoundFile) {

	soundEngine = createIrrKlangDevice();
	currentSound = 0;

	if(!soundEngine) {
		exit(0);
	}
}

HintergrundMusik::~HintergrundMusik() {
	soundEngine-&gt;drop();
}

void HintergrundMusik::spieleSoundThread() {

	soundFile = &quot;La Musica Notturna (Passa Calle).mp3&quot;;

	currentSound = soundEngine-&gt;play2D(soundFile.c_str(), false, false, true);

	while(spielt()) {
		Sleep(100);
	}

}

bool HintergrundMusik::spielt() {

	return !currentSound-&gt;isFinished();

}
</code></pre>
<p>und der Aufruf erfolgt halt in ner anderen Klasse:</p>
<pre><code class="language-cpp">private: System::Void HintergrundmusikAn_Click(System::Object^  sender, System::EventArgs^  e) {
				 if(HintergrundmusikAn-&gt;Checked::get()) {
					HintergrundmusikAus-&gt;Checked::set(false);

					HintergrundMusik backgroundSound;
					backgroundSound.spieleSoundThread();
				 }
			 }
</code></pre>
<p>Wenn ich die Checkbox anklicke spielt der auch den Sound ab, allerdings möchte ich eigentlich, dass</p>
<p>1. der Sound beim Programmstart abgespielt wird und nicht erst, wenn die Checkbox angeklickt wird und</p>
<p>2. das Programm nicht warten muss, bis die Sounddatei beendet ist - jetzt wird die Sounddatei abgespielt und nix anderes geht mehr - ich hab in C++ mit Threads noch keinerlei Erfahrung sammeln können..</p>
<p>Kann mir da jemand weiterhelfen?^^ <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2233453</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2233453</guid><dc:creator><![CDATA[Zel2491]]></dc:creator><pubDate>Tue, 17 Jul 2012 11:55:38 GMT</pubDate></item><item><title><![CDATA[Reply to Background Musik unter Window Forms on Tue, 17 Jul 2012 13:40:42 GMT]]></title><description><![CDATA[<p>Windows Forms und Musik sind in Standard-C++ nicht enthalten. In welches Forum darf ich dich verschieben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2233504</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2233504</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Tue, 17 Jul 2012 13:40:42 GMT</pubDate></item></channel></rss>