Picker Wheel or other widget for Music Selector

Been looking at the widgets to find a space-saving solution for my app.

I have about 7 songs/rhythm tracks the user should be able to play.  I also have widgets to PAUSE and STOP the music.  I have no space to put widgets to represent the music selections.  So, Picker Wheel seems a possible solution.

Can the picker wheel be used as such and when using the sample code at the University, how would I reference the labels in order to allow PLAY, PAUSE and STOP widgets to control the music?

If you think this is a stupid way to do this and can point me in another direction, I’m all eyes and ears.

Thanks for your help and advice!

local widget = require( “widget” )

– Create one tables to hold data for songs      

local songs = {}

– Configure the picker wheel columns

local columnData = 

{

    – Songs

    {

        align = “center”,

        width = 200,

        startIndex = 1,

        labels = { “Crazy Song”, “Insane Chant”, “Rasta Wrap”, “Find the Soundz”, “Karaoke”, “Jawbone Jam” }

    },

}

– Create the widget

local pickerWheel = widget.newPickerWheel

{

    left = display.contentWidth /2 -150,

    top = display.contentHeight - 220,

    font = “Bauhaus 93”,

    fontSize = 25,

    columnColor = { .1, .9, .1 },

    columns = columnData,

   

}

– This can be performed on a button tap, timer execution, or other event

local values = pickerWheel:getValues()

–[{Get the value for each column in the wheel (by column index)

local currentsong = values[1].value

]]–

print( currentsong )

Seems like a reasonable plan.  You could also use a widget.newTableView() as well.  The pickerView is based around the iOS design where there is a frame around the values and that frame has a fixed size.  The tableView can be resized to whatever size you need it to be.  The draw back is that there isn’t a way to get the current value but you have to respond to individual row’s being tapped.

Rob

Thanks for the heads up about the widget Table View.  As you said, it works in terms of size.  But I think I like the dynamic movement of the Picker Wheel.

That said, I also played around with the  newSegmentedControl and was able to “hook up” the audio tracks to each segment.

Following that same idea of the SegmentedControl “onPress” Listener, I was hoping to set up the Picker Wheel the same but using the “labels” instead.  I have the function looking like this and it isn’t working.  With a SegmentedControl the only difference is target.segmentNumber in place of target.labelNumber

I’m starting to think I can’t handle both of these widgets in the same way to play an audio file?

local function playAudio( event )

    local target = event.target

    if target.labelNumber == (2) then

        audio.play( vowels_sound, {channel = 27} )

    end

end

I’ve also made sure to code in the audio file and point it toward the 2nd label in the widget column.  Here’s all the code I’m using to try and get the Picker Wheel column label to trigger an audio file:

local widget = require( “widget” )

local vowels_sound = audio.loadSound( “VowelChant1.m4a” )

     

local function playAudio (event )

    local target = event.target

    if target.labelNumber == (2) then

        audio.play( vowels_sound, {channel = 27} )

    end

end

      

local songs = {}

local columnData = 

{

    {

        align = “center”,

        width = 200,

        startIndex = 3,

        labels = { “Phonics Song”, “Vowel Chant”, “Consonant Chant”, “Find the Sound”, “Karaoke”, “Phonics Jam” }

    },

}

– Create the widget

local pickerWheel = widget.newPickerWheel

{

    left = display.contentWidth /2 -150,

    top = display.contentHeight - 220,

    font = “KG Primary Penmanship”,

    fontSize = 25,

    columnColor = { .5, .7, .9 },

    columns = columnData,

    onPress = playAudio

}

Seems like a reasonable plan.  You could also use a widget.newTableView() as well.  The pickerView is based around the iOS design where there is a frame around the values and that frame has a fixed size.  The tableView can be resized to whatever size you need it to be.  The draw back is that there isn’t a way to get the current value but you have to respond to individual row’s being tapped.

Rob

Thanks for the heads up about the widget Table View.  As you said, it works in terms of size.  But I think I like the dynamic movement of the Picker Wheel.

That said, I also played around with the  newSegmentedControl and was able to “hook up” the audio tracks to each segment.

Following that same idea of the SegmentedControl “onPress” Listener, I was hoping to set up the Picker Wheel the same but using the “labels” instead.  I have the function looking like this and it isn’t working.  With a SegmentedControl the only difference is target.segmentNumber in place of target.labelNumber

I’m starting to think I can’t handle both of these widgets in the same way to play an audio file?

local function playAudio( event )

    local target = event.target

    if target.labelNumber == (2) then

        audio.play( vowels_sound, {channel = 27} )

    end

end

I’ve also made sure to code in the audio file and point it toward the 2nd label in the widget column.  Here’s all the code I’m using to try and get the Picker Wheel column label to trigger an audio file:

local widget = require( “widget” )

local vowels_sound = audio.loadSound( “VowelChant1.m4a” )

     

local function playAudio (event )

    local target = event.target

    if target.labelNumber == (2) then

        audio.play( vowels_sound, {channel = 27} )

    end

end

      

local songs = {}

local columnData = 

{

    {

        align = “center”,

        width = 200,

        startIndex = 3,

        labels = { “Phonics Song”, “Vowel Chant”, “Consonant Chant”, “Find the Sound”, “Karaoke”, “Phonics Jam” }

    },

}

– Create the widget

local pickerWheel = widget.newPickerWheel

{

    left = display.contentWidth /2 -150,

    top = display.contentHeight - 220,

    font = “KG Primary Penmanship”,

    fontSize = 25,

    columnColor = { .5, .7, .9 },

    columns = columnData,

    onPress = playAudio

}