In this paper, we discuss the use of knowledge for analyzing and retrieving music contents semantically. First, we present Context-based Music Recommendation (COMUS) ontology to reason desired user emotion state from context and user preference information in the ontology. COMUS is a music dedicated ontology in OWL constructed by incorporating domain specific classes for music recommendation into the Music Ontology, which include situation, mood and musical features. More specifically, we describe the ontologies of mood and situation in music using low-level features like pitch or duration and musical factors like tempo or rhythm. Our proposed ontology defines generic as well as domain-specific concepts whose detection is important for the analysis and description of music in a specific domain. As a novelty, our ontology can express detailed and complicated relations among the music, moods and situations, enabling users to find appropriate music for the music retrieval and recommendation application. We present some of the experiments we performed as a case-study for music recommendation.