Play .wav or .mp3 media using c-sharp

- Posted in Coding by
using System;

namespace PlayWav{    

    class Program {                

        static void Main(string[] args)
        {

            Console.Clear();            

            System.Media.SoundPlayer player = new System.Media.SoundPlayer();
            player.SoundLocation = "upbeat.wav";
            player.Play();
            Console.WriteLine("nn Press any key to exit...");
            Console.ReadKey();
        }

    }

}

Now, this is quite handy for small .wav files used as sound effects. But if you're going to play songs, you wanna use .mp3 format. That's not quite as simple. After some research, I found it's not difficult if you use a freely available library called NAudio. Your code must reference this library, whose code is contained in file NAudio.dll. I should note that the following code will suffice equally well whether you wish to play .wav or .mp3 files:

using System;
using NAudio;
using NAudio.Wave;

namespace PlayMp3{   

    class Program {                

        static void Main(string[] args)
        {

            Console.Clear(); 
            Console.WriteLine("n Press a key to play a 7-second segment from 'Somewhere Out There' (a 1986 song)");
            Console.ReadKey();
            using(var audioFile = new AudioFileReader("somewhere.mp3"))
            using(var outputDevice = new WaveOutEvent())
            {
                outputDevice.Init(audioFile);
                outputDevice.Play();
                while (outputDevice.PlaybackState == PlaybackState.Playing)
                {
                    System.Threading.Thread.Sleep(1000);
                }
            }
            Console.WriteLine("nn Press any key to exit...");
            Console.ReadKey();
        }

    }

}

Ensure single instance only using c-sharp

- Posted in Uncategorized by
Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    bool result;
    var mutex = new System.Threading.Mutex(true, "MakeThisAHighlyUniqueString", out result);

if (!result)
{
    MessageBox.Show("Another instance is already running.");
    return;
}           
Application.Run(new MainForm());
GC.KeepAlive(mutex);

Personal Bests

- Posted in Uncategorized by

Personal Bests


  • PB 1K: 6:36 (avpace 10'37“)
  • PB 1.0 mile: 9:18 (avpace 9'18”)
  • PB 4.0 mile: 40:18 (avpace 10'05“; 5/06/2019)
  • PB 6.25 mile: 1:00:32 (avpace 09'40”; 6/23/2019)
  • PB 8.00 mile: 1:30:16 (avpace 11'17“; 4/15/2019)

Past PB Overall Times At Given Distances

  • SB 6.25 mile: 1:01:48 on Thursday, 6/13/2019
  • TB 6.25 mile: 1:05:02 on Friday, 4/26/2019

Best Average Pace On 10+ Mile Runs

  • PB average pace during 10+ mile run: 11'23” on Thursday, 11/15/2018

Longest Run

  • PB longest run: 12.03 miles on Monday, 12/19/2018

My drawings

- Posted in Uncategorized by

I enjoy creativity, whether it takes the form of programming, writing, or painting. However, I engage much more in programming than in the latter two pursuits.

Here are some of the drawings and paintings I have done. You should click on the inline image to launch a full-size image in another browser tab. These aren't presented in any particular chronological order.

Most recently, I did this watercolor on canvas after re-reading Stephen King's Gunslinger series. I find the inexactitude of watercolor painting somehow freeing. It's a feeling of freedom, as less required concentration and attention to detail can result in faster work being done, with an accompanying heightening of freedom of expression. The gunslinger in that seven-book series is one of my favorite characters, ever. He was definitely not done justice by the 2017 move The Dark Tower.

As an aside, even if you're not generally a fan of Stephen King, you might really enjoy the Gunslinger novels. They aren't his typical horror shtick. They're a great blend of fantasy-action and grittiness. Just read the first of the series, The Gunslinger. You'll be hooked!

This next one is a colored-pencil work that I was really pleased with; it took about three hours to create.

This drawing is based on a picture in a magazine that I found just beautiful! I'm still trying to find the magazine's title. It was one I was browsing in my dentist's office. I talked the receptionist into color-printing the page with the photo, so that I could take it with it.

This would have been in early May, 2019. I'm really pleased that I chose colored pencils as my medium for this work. I really like the end result. Watercolors would also have been nice, I think.

Two people before a beautiful window, each lost in their own thoughts and yet companionably aware of one another. This city. This bustling mass of humanity. And we, for a few moments, stand in quietude, peace, considering our lives....

This next picture is an oil painting I did in October 2017 as a cover image for a novel I was working on at the time. I still haven't published the novel, but the cover photo is waiting for that day to come :) I call this painting Fastness. Note there is a fastness, or citadel, atop the cliffs/hills, overwatched by moonlight. I did this on a 20 x 24 " canvas, at a total time investment of about nine hours. Some artists experience the direct opposite, but I've always found working in oil more demanding than using watercolors. During 2017 I was doing a lot of C# programming. Consequently, I produced relatively few drawings and paintings. This work seemed to scratch an itch, and I didn't complete another graphical art project until February of 2018.

Page 10 of 10