You can't say Je parle à lui. The indirect object pronoun lui already "contains" the preposition. It also needs to come right after the verb. The proper way to say this would be: Je lui parle.
COD = Complément d'Objet Direct: it receives the action of the verb directly. You usually ask for it with "what" or "whom".
Tu manges une pomme. -- You're eating an apple (What are you eating?)
Marie boit du café. -- Marie is drinking some coffee. (What is she drinking?)
Tu l'as vue? -- Did you see her? (Whom did you see?)
COI = Complément d'Objet Indirect: it receives the action of the verb through a preposition. It always is preceded by a preposition in French version unless you're using indirect object pronouns like lui, me, te, etc.
Le prof parle aux étudiants. -- The professor is talking to the studends.
Le prof leur parle. -- The professor is talking to them.
Pierre me fait mal. -- Pierre is hurting me. (Note that "me" replaces "à moi")
Répondez à mon mail, svp. -- Please, answer my mail.