One.:
implement function: when the "playing" button, switch to the next screen and continue the original song playback progress
Two. Implementation methods and procedures
1. Idea: the first step. When you click on the button event and show it to the next interface, it launches to the singleton view we created (the second interface view was previously created as a singleton)
The second step. When you click on the page to play, if the current play as the fourth song, show is also the fourth, you do not need to play from the beginning, continue to play the current position, if it is the next one will need to play from the beginning (think clearly this logic judgment relationship)
2. Steps :
The first step is to implement the steps:
@interface Musiclisttableviewcontroller ()-(Ibaction) Didclickplayingbarbutton: (Uibarbuttonitem *) sender; @end
// Click the button to push to the second Singleton Object view page -(ibaction) Didclickplayingbarbutton: (Uibarbuttonitem *) sender {// Get the Singleton object method Musicplayerviewcontroller *playvc = [Musicplayerviewcontroller SHAREMUSICPLAYVC]; //show to the next page [Self.navigationcontroller showviewcontroller:playvc sender:self];}
The second step is to implement the steps:
In the method that the view will appear, make a judgment. History does not put the line label of the song is the same as the current subscript. If the same continues with the current song playback, if it is different, play it again.
1. Declare a property store to play the subscript of the song
@property (nonatomic,assign) Nsinteger currentindex; // History Store the subscript of the previous (old) music song used to temporarily save the playing song
// assign an initial value _currentindex =-1;
2. Judge the page that will appear on the view
Play music when #pragma mark---View is going to appear-(void) viewwillappear: (BOOL) animated{ [Super Viewwillappear : animated]; // determines whether the song clicked by the button is equal to the current if (_index = = _currentindex) {return; }
[Self prepareforplaying];}
Note: In this judgment there is a problem, if play the first song, subscript index is 0, then _index = _currentindex is also equal, then will not go to start playing that method, resulting in the first one can not play.
Workaround:
-(void) prepareforplaying{
_currentindex is used to temporarily store index play songs as a temporary storage variable = _index ; * Indexpath = [Nsindexpath indexpathforrow:_currentindex insection:0];
One of Sina Weibo project technology is playing button click