~danielholm/musicapp/trunk

« back to all changes in this revision

Viewing changes to MusicApp.qml

  • Committer: Daniel Holm
  • Date: 2013-05-13 14:49:06 UTC
  • Revision ID: admin@danielholm.se-20130513144906-hjefcuodsytfuqic
Added functions to get track data, worked on previous track function and start of database.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import Ubuntu.Components.ListItems 0.1 as ListItem
25
25
import Qt.labs.folderlistmodel 1.0
26
26
import QtMultimedia 5.0
 
27
import QtQuick.LocalStorage 2.0
27
28
 
28
29
MainView {
29
30
    objectName: i18n.tr("mainView")
95
96
 
96
97
    // previous and next track function
97
98
    function nextTrack() {
98
 
        console.debug(index) // print next songs filename
99
 
        playMusic.source = musicDir+trackQueue.get(index).file
 
99
        console.debug() // print next songs filename
 
100
        playMusic.source = musicDir+trackQueue.get(0).file
100
101
        playMusic.play()
101
102
        removedTrackQueue.append({"title": trackQueue.get(0).title, "artist": trackQueue.get(0).artist, "file": trackQueue.get(0).file}) // move the track to a list of preious tracks
102
103
        trackQueue.remove(index) // remove the track from queue
103
104
    }
104
105
 
 
106
    function previousTrack() {
 
107
        console.debug("Debug: Previous track was "+musicDir+removedTrackQueue.get(removedTrackQueue.count).file)
 
108
        // play the previous track
 
109
        playMusic.source = musicDir+removedTrackQueue.get(removedTrackQueue.count).file
 
110
        playMusic.play()
 
111
    }
 
112
 
105
113
    // end of track
106
114
    function hasTrackEnded() {
107
115
        if (playMusic.status.EndOfMedia) {
109
117
        }
110
118
    }
111
119
 
112
 
    // Queue function
113
 
    function addToQueue(songTrack) {
114
 
        console.debug("Debug: added "+songTrack+" to queue.")
115
 
        // move down the automatically added tracks by using index
116
 
    }
117
 
 
118
120
    // Get song title
119
 
    function getTrackInfo(source) {
 
121
    function getTrackInfo(source, type) {
120
122
        console.debug('Debug: Got it. Trying to get meta data from: '+source) // debug
121
123
        musicInfo.source = source
122
124
        musicInfo.pause()
123
 
        return musicInfo.metaData.title
124
 
    }
125
 
 
 
125
 
 
126
        // if title
 
127
        if (type == "title") {
 
128
            return musicInfo.metaData.title
 
129
        }
 
130
 
 
131
        // if artist
 
132
        else if (type == "artist") {
 
133
            return musicInfo.metaData.albumArtist
 
134
        }
 
135
 
 
136
        // if album
 
137
        else if (type == "album") {
 
138
            return musicInfo.metaData.albumTitle
 
139
        }
 
140
 
 
141
        // year
 
142
        else if (type == "year") {
 
143
            return musicInfo.metaData.year
 
144
        }
 
145
 
 
146
        // cover
 
147
        /*else if (type == "cover") {
 
148
            return musicInfo.metaData.cover
 
149
        }*/
 
150
    }
 
151
 
 
152
    // add track to database
 
153
    function addToDatabase(track) {
 
154
        // get the needed info of track
 
155
        title = getTrackInfo(track, title) // title
 
156
        artist = getTrackInfo(track, artist) // artist
 
157
        album = getTrackInfo(track, album) // album
 
158
        cover = getTrackInfo(track, cover) // cover
 
159
        year = getTrackInfo(track, year) // year of album relase
 
160
 
 
161
        // push to database
 
162
    }
 
163
 
 
164
 
 
165
    // run code to check music dir for new stuff
126
166
 
127
167
    // Music stuff
128
168
    Audio {
129
169
        id: playMusic
130
170
        source: ""
 
171
        /*onEndOfMedia: {
 
172
            console.debug("Deub: Track ended. Play next.") //debug
 
173
        }*/
131
174
    }
132
175
 
133
176
    // get file meta data
164
207
        ListElement {
165
208
            title: "Dancing in the Moonlight"
166
209
            artist: "Thin Lizzy"
167
 
            file: "something"
 
210
            file: "dancing"
168
211
        }
169
212
    }
170
213
 
208
251
 
209
252
                        onTriggered: {
210
253
                            console.debug('Debug: Prev track pressed')
211
 
                            console.debug(musicDir+removedTrackQueue.get(0).file) // print next songs filename
212
 
                            playMusic.source = musicDir+removedTrackQueue.get(0).file
213
 
                            playMusic.play()
 
254
                            //console.debug(musicDir+removedTrackQueue.get(0).file) // print next songs filename
 
255
                            //playMusic.source = musicDir+removedTrackQueue.get(0).file
 
256
                            //playMusic.play()
 
257
                            previousTrack()
214
258
                        }
215
259
                    }
216
260