Skip to content

Commit

Permalink
Crashing bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
smedic committed Feb 8, 2017
1 parent 07e2a23 commit 9e8df09
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public void onSkipToPrevious() {
@Override
public void onStop() {
super.onStop();
Log.d(TAG, "onStop: ");
stopPlayer();
//remove notification and stop service
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
Expand Down Expand Up @@ -449,6 +450,7 @@ private void seekVideo(int seekTo) {
private void stopPlayer() {
mMediaPlayer.stop();
mMediaPlayer.release();
mMediaPlayer = null;
}

/**
Expand All @@ -472,15 +474,15 @@ private YtFile getBestStream(SparseArray<YtFile> ytFiles) {
* Extracts link from youtube video ID, so mediaPlayer can play it
*/
private void extractUrlAndPlay() {
Log.d(TAG, "extractUrlAndPlay: extract url for video id=" + videoItem.getId());
final String youtubeLink = "http://youtube.com/watch?v=" + videoItem.getId();

String youtubeLink = "http://youtube.com/watch?v=" + videoItem.getId();
YouTubeUriExtractor ytEx = new YouTubeUriExtractor(this) {
@Override
public void onUrisAvailable(String videoId, String videoTitle, SparseArray<YtFile> ytFiles) {
if (ytFiles != null) {
YtFile ytFile = getBestStream(ytFiles);
try {
Log.d(TAG, "Start playback");
Log.d(TAG, "Start playback - video id: " + videoItem.getId());
if (mMediaPlayer != null) {
mMediaPlayer.reset();
mMediaPlayer.setDataSource(ytFile.getUrl());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ private Videos(String tableName) {
*/
public boolean create(YouTubeVideo video) {
if(checkIfExists(video.getId())){
Log.d(TAG, "create: existsssssss");
return false;
}
// Gets the data repository in write mode
Expand Down

0 comments on commit 9e8df09

Please sign in to comment.