Create audio player with button icon change in tableview or collectionVIew in iOS swift

  Problem:

I want to create an tableview with audio player.If the user taps inside the tableview button it will change the icon of the button and user can able to play and pause the audio.

Solution:

In tableview cell add the button with its target.Also set the button title and title image for both normal and selected state.

Inside the target if button is selected then change the state of the button and play the player.

If button is unselected then pause the player or stop the player.

If you had different targets for cell then must be use remove the other target's after that add the target that you want to apply.

Also want to implement the willdisappear method must be handle to stop the player and change the state of the button.

For the above you want to set the tag to the button and access the cell using the tag.

If the player reached the endtime of the audio then the delegate method will be called "Didfinishplaying".

Inside that you can change the state of the button and stop the player.

If you want to stop the player while playing and user wants to play other audio.

Then you have to create one global variable and in user tapped the button then save the tag inside that variable.If user taps another button then stop the previous one using the variable after that update the variable with newly tapped button and play the audio.


Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift