Showing posts with label Coding. Show all posts
Showing posts with label Coding. Show all posts

Tuesday, July 31, 2007

SharePod SDK Code Samples

I've been getting lots of questions about how to use the SharePod SDK and to provide more code samples... so thats what I'm going to do. They will be added to the SharePod SDK page and to the SDK download.

This shows how easy it is (under 10 lines including some error checking!) to get a list of tracks on your iPod:

IPod iPod = null;
try
{
IPod iPod = SharePod.GetConnectediPod();
}
catch (BaseSharePodException ex)
{
MessageBox.Show(ex.Message);
return;
}
foreach (Track track in iPod.Tracks)
{
Debug.WriteLine(String.Format("{0} - {1} - {2}",
track.Title, track.Artist, track.Album);
}

Friday, May 18, 2007

SharePod 3.0 Released!

Phew, at long last SharePod 3.0 is available to download! I'm really happy with it, its the most significant release since 1.6 when the UI was redesigned.

I'm guessing the next week will be responding to bugs/install problems then im going to take a bit of a break :)

Feel free to comment with questions/issues/bugs etc, I check it regularly.

Enjoy, im off to sleep!

Wednesday, May 9, 2007

Screenshots


Heres a teaser of the new SharePod UI :) SharePod is ready to go out (its even all zipped up) but I just want to wait a day or two to investigate an issue one of my beta testers has. We're not sure if it is SharePod or his system yet but for the sake of a couple of days I think its worth it to wait and fix as many problems before the mass release as possible! thanks for comments

Tuesday, May 1, 2007

SharePod 3.0 Available Soon!

Well I've been working pretty hard on SharePod. (Most nights after work..!)
Rewriting from scratch always seems like a good idea at the start of the project but at the end it justs makes you realise how much the previous version did!!

The list of new features and fixes for old issues is quite large now, so the next mission will be re-doing the website as the info contained there will be out of date within a week!! Yep thats right, Im working towards releasing SharePod 3.0 into the wild within a week :)

The class library for integrating SharePod into your own applications will be available a couple of weeks after that (once I have had time to tidy it up and fix any immediate problems).

The notable thing which will be missing on release day is album art - it has been too much work to do it right now and I would rather release new features like that after a successful release :)

I did get video support working, so if you have a iPod-ready video (SharePod doesnt do video re-encoding, there are enough great apps to do that already) you can copy it onto your iPod just like a music file.

One feature I'm really happy about is the ability to drag files in SharePod and drop them straight into Explorer, just like WinZip!! This makes copying music/videos to your computer really easy. Of course you can drag files from Explorer back into SharePod too!

Thanks for everyones help and support so far, hope SharePod 3.0 lives up to expectations (I think it will..!)

Wednesday, April 11, 2007

SharePod Progress Pt. 2

Well I've just realised its been over a week(!) since I last posted...its crazy how time can fly by sometimes.

I didnt have much time over the Easter break to work on SharePod, but here is the current status:

  • iPod Songs/Playlists reading and writing
  • Play Counts reading (the number of times / last time youve listened to a song). In SharePod 2 this file wasn't read, so if you didnt use iTunes, your Play Counts werent updated.
  • iPod Shuffle alpha support. I say alpha because (right now) I dont have a Shuffle to test it on, but I am writing the Shuffle database file correctly as far as I can tell.
As I said in a previous post, I am writing SharePod in 2 parts - the iPod functionality and then the actual SharePod application over the top of it.

The application part of this I haven't really started on, but will be concentrating on this soon so I can start alpha testing it on my own iPods properly.

There is no particular release date in my mind yet, but I want to work solidly on it for the next 2 weeks at which point I hope to be able to release. Probably not feature complete, but something more usable and stable than the current versions.

If there are any UI designers out there who have great ideas for the direction of the SharePod UI send me an email! (jeff@sturm.net.nz)

Monday, April 2, 2007

SharePod Version 3 Progress

I've been working on SharePod v.3 for about 3 nights now. (I work during the day and usually busy in the weekend so nights are all I have..)

Progress so far has been really good, its coming together so much faster than the original SharePod 1.0, where every part of the iPod's internal database had to be investigated. Although there will be no current-version SharePod code in Version 3, all the logic has been transferrable to the new codebase.
I have a fully working iTunesDB parser which is built from the start to allow easy reading and writing. The current codebase by comparison had the write ability hacked on top, so there were some things it was just too hard to support (editing of song tags, for example)

The next step is finish the writing part of the code - right now it just writes back the file as it reads it, but it should take into account new songs added/removed, tags changed and playlists modified.

Once that is done (hopefully tonight), the plan is:
- Playcounts file parser (to update the number of times a song has been played etc)
- Artwork file parser (to read the album art descriptions)
- Code to actually read, display and import the iPod-formatted artwork
- iPod Shuffle file reading/writing
- Video import


While I am doing all this, I am also trying to come up with a sensible API to expose to other programs wanting to use SharePod functionality! So the next few weeks will be busy ones!

Friday, March 30, 2007

A New SharePod

I've had loads of questions about Sharepod - am I still working on it, how does it work on Vista, can it handle images/videos etc etc.

For quite a while now I have avoided doing large scale work on SharePod - just fixing it when iTunes changes its file format or someone finds a bug. One reason for this is I started writing it about 3 years ago now and had got a bit bored of it.

The other reason is 90% of the codebase is Visual Basic 6 which is an old language these days and not something I want to keep working with! Originally VB6 was used because at the time most computers did not have the .NET framework installed and it went against my idea of no installation and just one .exe file. (not that that worked out too well in practice..!)

A couple of weeks ago, after a bunch of emails about the difficulty of installing SharePod on Vista and talking to some friends about their projects, I got all motivated again :)

I am currently completely rewriting SharePod! (in C# .NET!)
This has a bunch of advantages - enabling me to include new features you've have been asking for and fixing most (all?) installation issues. A total rewrite seems a bit daunting, but all the work which has gone into SharePod over the past 3 years should hopefully make it easier than it seems!


The major new features I am planning are currently:
- Edit song tags on the iPod
- More song details (dates, play counts...)
- Support for iPod Shuffles (lots of you have been asking for this one!)
- Album art
- Video support


I am planning to break SharePod into two parts - the SharePod application itself (which will be completely free as always!), and a SharePod class library.
The class library will allow other developers/companies to integrate SharePod functionality into their own applications with minimal effort. I would like this to be available as shareware with a royalty-free licence.

Monday, February 5, 2007

GoDaddy Support(?)

I recently registered 2 new websites - TVTorrentsOnline and G-CalMobile.com.

Diggnation (a great tech and beer podcast) recommend GoDaddy, so I went with them.

The initial sign-up was pretty painless, although their website is covered with ads and quite hard to navigate. The first warning sign (which I ignored) is there is no monthly fee option - you have to pay for at least 1 year of hosting in advance. And worse, I found later this is non-refundable!

After fumbling through the confusing Control Panel, I managed to get the domain names pointing at test pages. 'All good!', I thought. Unfortunately, that turned out to be the highlight of my GoDaddy experience so far.

Both my new websites use ASP.NET 2.0, and both make use of outgoing connections. TVTorrentsOnline scrapes torrent data from Mininova, and G-CalMobile uses Google Calendar's API to provide calendar access to mobile devices.
Neither worked when uploaded to GoDaddy. I searched through the help pages and found a reference to a proxy server to use for outgoing connections. Great, tried it, but the security setup at GoDaddy doesn't allow my code to manually set the proxy.

At this point I sent my first support request to GoDaddy support, asking how to use outgoing connections with ASP.NET and specifying what I had already tried. The reply was to the effect of 'Yes, there is a proxy server, but it is automatically configured for ASP.NET, and you don't need to manually set it in code'. And ignoring the fact I had tried that initially and it didnt work.

I sent a second support request, saying it still wasnt working. This time I got a reply from a different person who said 'Yes, there is a proxy, and yes you do need to set it manually'. He said he could not help with user code (fine) and basically as far as GoDaddy was concerned I was on my own (not fine, it was a server configuration issue)

By this point I was getting a bit pissed off, and looked around the web for other GoDaddy support stories. There are loads! One post I found said to explicitly ask for the request to be "escalated", which would hopefully send it to 2nd line support (who may actually have some idea what they are doing!)

So, a third email later, using the magic words and repeating everything I had told the first two, I finally got a reply from Advanced Support, who simply said 'The proxy configuration problem has been resolved'. No explanation or apologies of course! And lo and behold, outgoing connections suddenly started working, a week after my first complaint!

It was a real eye-opener to me, if you aren't sure of your technology, or not as stubborn as a horse, the GoDaddy support people will just brush your problems away as code errors. I almost ended up with a bill for a years useless hosting!

In the end, I still haven't got G-CalMobile running at GoDaddy. The security is just too locked down for the Google APIs to work.

If anyone is looking for really good quality hosting and great customer service, OpenHost are a great company and that is where sturm.net.nz is hosted. I go over my monthly bandwidth allowance every month and they never charge me extra (until now maybe...!)

So.. moral of the story, GoDaddy might be the #1 domain registrar, but stay away from them if you want quality hosting and service.

Thursday, November 30, 2006

Update GUI controls in multi-threaded WinForm apps in .NET 2.0

.NET 2.0 by default doesn't allow code running in a separate thread to update controls created by the main GUI thread. So if you create a new thread, that thread cannot call Textbox1.Text = "Hello World" for example.

There are two ways around this - set the CheckForIllegalCrossThreadCalls flag to false. This will allow .NET 1.1 controls to work as they did under the 1.1 framework.

The proper way to do it (according to Microsoft) is to create a method to do the control update, then call that method (on the main thread) through a delegate.

Its always easiest to see some code example. In this example, I am hiding/showing the main form from a worker thread.

At the top of my form class I have the following:
delegate void SetFormVisibleCallBack(bool visible);


The actual method to set the Visible flag is:

private void SetFormVisible(bool visible)
{
if (this.InvokeRequired) /*returns true if we are calling the method from a worker thread.*/
{
SetFormVisibleCallBack visCB = new SetFormVisibleCallBack(SetFormVisible);
this.Invoke(visCB, new object[] { visible });
}
else
{
this.Visible = visible;
}
}

If called from a worker thread, SetFormVisible Invoke()'s the main thread to call the SetFormVisible method again. When it does so, this.InvokeRequired will be false, allowing the Visible property to be directly set.

Now, to set the form's Visible property from the main thread or a worker thread, simply call:
this.SetFormVisible(false);


There is an Microsoft Help article on this, but its unnecessarily hard to follow.

Wednesday, November 29, 2006

Sound Detection using C#

I few weeks ago I needed to detect sound through a microphone. What I wanted to do was turn on a computer screen when a sound was heard (talking, clapping etc). After a long google session, all I turned up were several expensive sound detection systems and a piece of VB6 code which sets up the soundcard for sampling using the Win32 API.

Instead of porting all the API code to C#, and having an 'interesting' history with VB6 (who doesn't), I hacked the VB6 code into a dll. This library now provides a list of available recording devices, listens to the microphone and raises an event when the volume is greater than a given threshold. And best of all its easily accessible from .NET code.

Internally, it
  • Grabs a buffer of 8-bit samples from the soundcard. 8-bit means each sample value is 0-256, with 127 being silence.
  • Loops through the buffer, and if there is a value greater than the threshold, raise an event

Get the Detector library (+ source + sample C# application)
Feel free to use it in your own projects. Enjoy!