Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Read/Detect Current Volume Playing

As title, I'm trying to handle/read volume that's currently playing on system.

Before open this thread, I made some tries in the last 2 days, and I tried a lot of different projects, since I though that an easy thing.

Only at end, I realized that I just got Current System Volume, all times, in all projects I made, but the problem is that I need to get the value of playing audio, in other terms, detect when a sound get played.

So I started making other searches, I built another project, realizing at end, that progress bars just print value of audio input on microphone, that's quite different from volume I'm trying to read.

Just for make you understand what am I asking, here is a screenshot of that I want to read.
[Image: volume2.png]
As image, I need to read/get/capture value of green bar.
In other terms, I want to make an action, when a sound is played on windows.
I'm searching yet, if someone know a solution, I would be really grateful.
[Image: giphy.gif]
32 secs after reading this post:

[Image: loK92C4.png]

Hint:
Code
PM> Install-Package CSCore

Hope it helps.
I donwloaded that CSCore, and added as a reference.
It looks nice, but I really don't know how to go on.
I'm stuck at start.
If I made all good, I succesfully got list of all devices, but I don't know how to print them in a msgbox, or in a combo.
PS : I used intuition on Imports, since documentation seems to be poor, and did not specified that.

Code
Imports CSCore
Imports CSCore.Codecs
Imports CSCore.SoundOut.DirectSound

Public Class Form1

    Public Function EnumerateDirectSoundDevices() As IEnumerable(Of DirectSoundDevice)
        Return New DirectSoundDeviceEnumerator().Devices
    End Function

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            EnumerateDirectSoundDevices()
        Catch ex As Exception
            MsgBox("1 - " & ex.Message)
        End Try
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        MsgBox(????? text for combo list ?????)
    End Sub
End Class

Anyway, in another few code snippets, I understood how to play mp3 files, helping with documentation.
Since I did not see other guides, I really don't know how to detect when ANY sound play.
I guess I should use SoundIn stuffs.
[Image: giphy.gif]
(Dec 2, 2016 04:44 AM)aGFjaw-- Wrote:  I donwloaded that CSCore, and added as a reference.
It looks nice, but I really don't know how to go on.
I'm stuck at start.
If I made all good, I succesfully got list of all devices, but I don't know how to print them in a msgbox, or in a combo.
PS : I used intuition on Imports, since documentation seems to be poor, and did not specified that.

Code
Imports CSCore
Imports CSCore.Codecs
Imports CSCore.SoundOut.DirectSound

Public Class Form1

    Public Function EnumerateDirectSoundDevices() As IEnumerable(Of DirectSoundDevice)
        Return New DirectSoundDeviceEnumerator().Devices
    End Function

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            EnumerateDirectSoundDevices()
        Catch ex As Exception
            MsgBox("1 - " & ex.Message)
        End Try
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        MsgBox(????? text for combo list ?????)
    End Sub
End Class

Anyway, in another few code snippets, I understood how to play mp3 files, helping with documentation.
Since I did not see other guides, I really don't know how to detect when ANY sound play.
I guess I should use SoundIn stuffs.

EnumerateDirectSoundDevices
is a function that returns an IEnumerable. you cant just call it and expect something to happen.
A wise man once said: Give a man a fish, and you feed him for a day; teach a man to fish, and you feed him for life
RYDIOO HackForums 11-30-2016 BC 🤣

https://github.com/filoe/cscore/blob/mas...ion.cs#L68

#2 Hint:

[Image: yafWJ5r.png]

Literally less than 10 lines of code.
Really don't know......



I'm working on other 2 projects

- The first one with Managed DirectX it print a lot of lines like in your screenshoot, but 100 lines of codes are needed, and it works only with microphones, or mixing stereo, but not all computers have mixing stereo in Registration Devices...

- The second, it's resulting pretty easier, and it uses CoreAudioApi.dll, Scilloscope.dll, TraceBar.dll, it's not end yet but it seems to work, and it seems that mixing stereo is not needed, but I'm not sure on that.
If yes, I'll have to add a timer, that check if value of my Vertical Progress Bars is > 0

- There finally is a third project, your one, using CSCore, you said that less than 10 lines of code for :
1 - check costantly if a sound got played
2 - print sound played status
I opened your github link, but I'm equally stuck before begin, since I can just try covert C# to VB.NET, and since I'm too much wont to create projects with a Form.
[Image: giphy.gif]
(Dec 2, 2016 05:43 AM)aGFjaw-- Wrote:  Really don't know......



I'm working on other 2 projects

- The first one with Managed DirectX it print a lot of lines like in your screenshoot, but 100 lines of codes are needed, and it works only with microphones, or mixing stereo, but not all computers have mixing stereo in Registration Devices...

- The second, it's resulting pretty easier, and it uses CoreAudioApi.dll, Scilloscope.dll, TraceBar.dll, it's not end yet but it seems to work, and it seems that mixing stereo is not needed, but I'm not sure on that.
If yes, I'll have to add a timer, that check if value of my Vertical Progress Bars is > 0

- There finally is a third project, your one, using CSCore, you said that less than 10 lines of code for :
1 - check costantly if a sound got played
2 - print sound played status
I opened your github link, but I'm equally stuck before begin, since I can just try covert C# to VB.NET, and since I'm too much wont to create projects with a Form.
You take on way too intensive projects for your skills...
(Dec 2, 2016 06:27 AM)Ninja Wrote:  You take on way too intensive projects for your skills...

I probably completed the 2nd project since I did not understood CSCore ...
... Yes, unfortunately I'll never learned 100% of coding.

In the last 8 years, I learned a lot of things, I pass whole days studing new things, or accepting new challenges, I also have a very nice mind.
But I need clear guides, and a lot of practice and experiments to learn a thing.
My method consist to have an idea of what I'm trying to learn, and to try to understand each minimal thing of an argument, I make myself a lot of questions (typical of my character), trying to find answers.
Unfortunately on coding, I have never built a good knowledge base.

I just use VB.NET literally since always, I learned the basics, and using Google and my mind, I'm almost always had success to code every thing I want, also complex things.
Yes, application will work, but I know surely exist in way to do same things I do with half of code lines, or using half of machine resources, and memory.
The thing I thing I Should do, could be to submit all my project I compiled since years to a mentor, or community, with a little comment That say what the application should do coded, making him understand my coding style, and so my errors.
[Image: giphy.gif]
As I see you're stuck i'll show you my solution, but do not get used to it 👍

Spoiler (Click to View)

Feel free to ask something you don't understand.

10 lines, 18 lines... Who cares 🤣
Thanks a lot for code, I just integrated it into my application, that will end within 1-2 days.

Except some stuffs I don't understand, I noticed you use a completely different format when printing info, in that case in WriteLine.
-I did not use $, I thing it's not necessary.
-I use & for concat strings and vars.
-I don't use Return.
-I usually write always Public Function.
-I declare Global vars, and not only for a function.
-I never declare an ""item"" with code, like you done with the Timer.
-Sometimes I use a lot of Timers and Sleep() for doing some stuffs.
-In the past I used a lot goto-label until I read that's really highly bad, for the machine memory placement, and that can cause application crash.
In the last projects, I'm ALWAYS using Try, Catch statement, the whole code is under these statement, I don't know if it's good, I used that only for debbugging purposes in the past, now I'm leaving that in all projects, assigning an Error ID each statement, like MsgBox("Error no.1 - " & ex.Message)

In other terms, you surely have a better coding style than me.
[Image: giphy.gif]

Checkout Jetbrains resharper. It will give you hints on how to improve your code readability. IE method and field modifiers, object initialization, and a lot of other things.

I would post references to some of the things I mentioned but this is my first post.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by unknown321Oct 23, 2021 09:22 PM 4 194 Oct 23, 2021 09:22 PM
Last Post: #Kat
[Python] by jailbotJul 15, 2019 06:45 AM 5 213 Jul 15, 2019 06:45 AM
Last Post: jailbot
[.NET] by Neos07Jan 25, 2019 06:53 AM 1 325 Jan 25, 2019 06:53 AM
Last Post: Dotexe