app/src/main/java/com/smedic/tubtub/BackgroundAudioService.java
private void extractUrlAndPlay() {
        final 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 = ytFiles.get(YOUTUBE_ITAG_140);
                    if (ytFile == null) {
                        ytFile = ytFiles.get(YOUTUBE_ITAG_18);
                    }
                    try {
                        Log.d(TAG, "Start playback");
                        if (mMediaPlayer != null) {
                            mMediaPlayer.reset();
                            mMediaPlayer.setDataSource(ytFile.getUrl());
                            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                            mMediaPlayer.prepare();
                            mMediaPlayer.start();
                        }
                    } catch (IOException io) {
                        io.printStackTrace();
                    }
                }
            }
        };
        ytEx.execute(youtubeLink);
    }
/**
     * Extracts link from youtube video ID, so mediaPlayer can play it
     */
Extracts link from youtube video ID, so mediaPlayer can play it
Extracts link from youtube video ID so mediaPlayer can play it
private void extractUrlAndPlay() {
        final 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 = ytFiles.get(YOUTUBE_ITAG_140);
                    if (ytFile == null) {
                        ytFile = ytFiles.get(YOUTUBE_ITAG_18);
                    }
                    try {
                        Log.d(TAG, "Start playback");
                        if (mMediaPlayer != null) {
                            mMediaPlayer.reset();
                            mMediaPlayer.setDataSource(ytFile.getUrl());
                            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                            mMediaPlayer.prepare();
                            mMediaPlayer.start();
                        }
                    } catch (IOException io) {
                        io.printStackTrace();
                    }
                }
            }
        };
        ytEx.execute(youtubeLink);
    }
private void extractUrlAndPlay ( ) { final 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 = ytFiles . get ( YOUTUBE_ITAG_140 ) ; if ( ytFile == null ) { ytFile = ytFiles . get ( YOUTUBE_ITAG_18 ) ; } try { Log . d ( TAG , "Start playback" ) ; if ( mMediaPlayer != null ) { mMediaPlayer . reset ( ) ; mMediaPlayer . setDataSource ( ytFile . getUrl ( ) ) ; mMediaPlayer . setAudioStreamType ( AudioManager . STREAM_MUSIC ) ; mMediaPlayer . prepare ( ) ; mMediaPlayer . start ( ) ; } } catch ( IOException io ) { io . printStackTrace ( ) ; } } } } ; ytEx . execute ( youtubeLink ) ; }
Extracts link from youtube video ID, so mediaPlayer can play it
Extracts link from youtube video ID so mediaPlayer can play it