im trying to write my own app to store my music on SQL server using MVP and interfaces Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Music.Presenter.interfaces; using Music.Entities; using Music.Services.Interfaces; using Music.Services; using System.IO; namespace Music.Presenter { public class MusicPresenter:IMusicPresenter { #region IMusicPresenter Members //Error 1 Cannot create an instance of the abstract class or interface //'Music.Services.Interfaces.IMusicService' //C:\Projects\MusicProgram\Music.Presenter\MusicPresenter.cs //22 34 Music.Presenter IMusicService MService =[U] new IMusicService();[/U] public string[] GetFileList(string Folder) { string[] locations = MService.BuildLibrary(Folder); return locations; } public bool CreateLibrary(IList<MP3> FileList) { throw new NotImplementedException(); } public bool UpdateLibrary(IList<MP3> FileList) { throw new NotImplementedException(); } public MP3 GetFileInfo(string Location) { throw new NotImplementedException(); } #endregion } } now i get an error trying to implement the interface yet MService.BuildLibrary(Folder); is picked up fine what am i missing here? the MService project builds fine im guessing i just have my syntax wrong or something
//Error 1 Cannot create an instance of the abstract class or interface //'Music.Services.Interfaces.IMusicService' //C:\Projects\MusicProgram\Music.Presenter\MusicPresenter.cs //22 34 Music.Presenter
Right, you can't create an instance of an interface. You have to create an instance of a class that implements that interface
There's a great site out there providing libraries to do just that ... I started doing a bit of this to look at WPF apps... but the idea fizzled This is nowhere complete -- but you'll get the idea (its only prototype stuff) Code: 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 System.IO; namespace Mp3Thing { public partial class Form1 : Form { List<Mp3Tag> tags = new List<Mp3Tag>(); public Form1() { InitializeComponent(); } private void toolStripButton1_Click(object sender, EventArgs e) { if (folderBrowserDialog.ShowDialog(this) == DialogResult.OK) { foreach (string f in Directory.GetFiles(folderBrowserDialog.SelectedPath)) { byte[] b = File.ReadAllBytes(f); int offset = b.Length - 128; byte[] tag = new byte[128]; Array.Copy(b, offset, tag, 0, 128); tags.Add(new Mp3Tag(tag)); } } } } class Mp3Tag { int[] _tagLengths = new int[] { 3, 30, 30, 30, 4, 30, 1 }; string _tag; string _songname; string _artist; string _album; string _year; string _comment; string genre; public Mp3Tag(byte[] tag) { int index = 0; _tag = Encoding.Default.GetString(tag, index, _tagLengths[0]); index += _tagLengths[0]; _songname= Encoding.Default.GetString(tag, index, _tagLengths[1]); index += _tagLengths[1]; //_artist; //_album; //_year; //_comment; //_genre; } } } try here: found this with a google http://www.codeproject.com/KB/files/tagreader.aspx
There's also plenty of open-and-free-to-use libraries that can handle reading/writing/etc of ID3 tags... i'm actually using one (id3Lib i think) for a project i'm working on in my spare time (which there is WAY too little of... both my GF and my xbox feel a bit neglected right now)