ios - fatal error: unexpectedly found nil while unwrapping an Optional value play audio files -


I am using a menu that shows a list of songs on the right, while clicking on that play button The code will be available for the following:

  Fancy Place selected Song (Sender: UIButton) {If sender.titleForState (UIControlState.Normal) == "Play" {sender.setTitle (" Stop ", forState: UIControlState! .normal) if player = zero {player.stop ()}} else {if player = not equal, then {{player.playing player.stop () on cell = tblSongsList.cellForRowAtIndexPath (NSIndexPath (ForRow: lastPlayIndex, insec Tion: 0)) btn: UIButton = cell .contentView.viewWithTag (11) as UIButton btn.setTitle ("Stop", forState: UIControlState.Normal)}} sender.setTitle ("Play", forState: UIControlState .Normal) playIndex = Sender Title forrestate (UIControlState.Selected) ?. TOI NT () var Item Collection: MPMediaItemCollection! = ArrData.objectAtIndex (playIndex!) As MPMediaItemCollection if itemcolletion! = Zero {var item: MPMediaItem! = Itemcolletion.representativeItem MPMediaItem if item! = Zero {var itemURL: NSURL! = Item.valueForProperty (MPMediaItemPropertyAssetURL) NSURL if itemURL = Zero {player = AVAudioPlayer! (ContentsOfURL: itemURL, Error: Zero)! Player = zero {player.prepareToPlay () player.play () lastPlayIndex = playIndex if! }}}}}}  

This gives accident sometime after usually 10-15 songs. Help me

option and try change for example

  var item archive: MPMediaItemCollection! = ArrData.objectAtIndex (playIndex!) As MPMediaItemCollection if itemcolletion! = Zero {var item: MPMediaItem! = Itemcolletion.representativeImem if item as MPMediaItem! = Zero { 

to

  var itemcolletion: MPMediaItemCollection? = ArrData.objectAtIndex (playIndex!) As? MPMediaItemCollection if itemcolletion! = Zero {var item: MPMediaItem? = Item Coalition! As .representativeItem? MPMediaItem if item! = Zero { 

As you can see, item compilation and item are options now before you were forced to use them "like" but now you " You can use? And check the price before using it.

Let me know that this works.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -