1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development c# interface problem

Discussion in 'Software' started by yakyb, 19 Apr 2008.

  1. yakyb

    yakyb i hate the person above me

    Joined:
    10 Oct 2006
    Posts:
    2,064
    Likes Received:
    36
    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
     
  2. shadow12

    shadow12 I lie

    Joined:
    30 Sep 2007
    Posts:
    231
    Likes Received:
    1
    What does the error say exactly?
     
  3. Adrir

    Adrir Aspiring Game Developer

    Joined:
    15 Apr 2008
    Posts:
    38
    Likes Received:
    0
    Is IMusicService abstract?
     
  4. yakyb

    yakyb i hate the person above me

    Joined:
    10 Oct 2006
    Posts:
    2,064
    Likes Received:
    36
    //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
     
  5. glaeken

    glaeken Freeeeeeeze! I'm a cawp!

    Joined:
    1 Jan 2005
    Posts:
    2,041
    Likes Received:
    50
    Right, you can't create an instance of an interface. You have to create an instance of a class that implements that interface
     
  6. Adrir

    Adrir Aspiring Game Developer

    Joined:
    15 Apr 2008
    Posts:
    38
    Likes Received:
    0
    I agree.
     
  7. yakyb

    yakyb i hate the person above me

    Joined:
    10 Oct 2006
    Posts:
    2,064
    Likes Received:
    36
    yep works now thanks

    next problem is that i need to read ID3 tags using Vista!!
     
  8. Hepath

    Hepath Minimodder

    Joined:
    20 Oct 2003
    Posts:
    730
    Likes Received:
    0
    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
     
  9. BentAnat

    BentAnat Software Dev

    Joined:
    26 Jun 2008
    Posts:
    7,230
    Likes Received:
    219
    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)
     

Share This Page