当前位置: 首页>>代码示例>>Java>>正文


Java YtFile类代码示例

本文整理汇总了Java中at.huber.youtubeExtractor.YtFile的典型用法代码示例。如果您正苦于以下问题:Java YtFile类的具体用法?Java YtFile怎么用?Java YtFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


YtFile类属于at.huber.youtubeExtractor包,在下文中一共展示了YtFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: playYoutube

import at.huber.youtubeExtractor.YtFile; //导入依赖的package包/类
public void playYoutube(final Context context, String url) {
    YoutubeManager.getInstance().startParseYoutubeUrl((Activity) context, url, new OnYoutubeParseListener() {
        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {

        }

        @Override
        public void onUrisAvailable(String videoId, String videoTitle, SparseArray<YtFile> ytFiles) {
            KLog.v(TAG, "onYoutube id: " + videoId);
            KLog.v(TAG, "onYoutube title: " + videoTitle);
            startPlayer(context, videoTitle, ytFiles);
        }
    });
}
 
开发者ID:TakumaMochizuki,项目名称:Komica,代码行数:21,代码来源:YoutubeManager.java

示例2: extractUrlAndPlay

import at.huber.youtubeExtractor.YtFile; //导入依赖的package包/类
/**
 * Extracts link from youtube video ID, so mediaPlayer can play it
 */
private void extractUrlAndPlay() {
    String youtubeLink = Config.YOUTUBE_BASE_URL + videoItem.getId();
    deviceBandwidthSampler.startSampling();

    new YouTubeExtractor(this) {
        @Override
        protected void onExtractionComplete(SparseArray<YtFile> ytFiles, VideoMeta videoMeta) {
            if (ytFiles == null) {
                // Something went wrong we got no urls. Always check this.
                Toast.makeText(YTApplication.getAppContext(), R.string.failed_playback,
                        Toast.LENGTH_SHORT).show();
                extractUrlAndPlay();

            } else {
                deviceBandwidthSampler.stopSampling();
                YtFile ytFile = getBestStream(ytFiles);
                try {
                    if (mMediaPlayer != null) {
                        mMediaPlayer.reset();
                        mMediaPlayer.setDataSource(ytFile.getUrl());
                        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                        mMediaPlayer.prepare();
                        mMediaPlayer.start();
                        handleSeekBarChange(videoItem.getId());
                        sendBroadcast(videoItem.getDuration());
                    }
                } catch (IOException io) {
                    io.printStackTrace();
                }
            }
        }
    }.execute(youtubeLink);
}
 
开发者ID:pawelpaszki,项目名称:youtube_background_android,代码行数:37,代码来源:BackgroundAudioService.java

示例3: getYoutubeDownloadUrl

import at.huber.youtubeExtractor.YtFile; //导入依赖的package包/类
private void getYoutubeDownloadUrl(String youtubeLink) {
    YouTubeUriExtractor ytEx = new YouTubeUriExtractor(this) {

        @Override
        public void onUrisAvailable(String videoId, String videoTitle, SparseArray<YtFile> ytFiles) {
            mainProgressBar.setVisibility(View.GONE);
            PD.dismiss();
            if (ytFiles == null) {
                TextView tv = new TextView(DownloadActivity.this);
                tv.setText("Update app");
                tv.setMovementMethod(LinkMovementMethod.getInstance());
                mainLayout.addView(tv);
                return;
            }
            formatsToShowList = new ArrayList<>();
            for (int i = 0, itag; i < ytFiles.size(); i++) {
                itag = ytFiles.keyAt(i);
                YtFile ytFile = ytFiles.get(itag);
                Log.d("asdasd", "onUrisAvailable: "+ ytFile.getUrl());
                if (ytFile.getMeta().getHeight() == -1 || ytFile.getMeta().getHeight() >= 360) {
                    addFormatToList(ytFile, ytFiles);
                }
            }
            Collections.sort(formatsToShowList, new Comparator<YtFragmentedVideo>() {
                @Override
                public int compare(YtFragmentedVideo lhs, YtFragmentedVideo rhs) {
                    return lhs.height - rhs.height;
                }
            });
            for (YtFragmentedVideo files : formatsToShowList) {
                addButtonToMainLayout(videoTitle, files);
            }
        }
    };
    ytEx.setIncludeWebM(false);
    ytEx.setParseDashManifest(true);
    ytEx.execute(youtubeLink);

}
 
开发者ID:vyasgiridhar,项目名称:Youtube-Downloader,代码行数:40,代码来源:DownloadActivity.java

示例4: getBestStream

import at.huber.youtubeExtractor.YtFile; //导入依赖的package包/类
/**
 *
 * @param ytFiles Array of available streams
 * @return Audio stream with highest bitrate
 */
private YtFile getBestStream(SparseArray<YtFile> ytFiles) {

    connectionQuality = ConnectionClassManager.getInstance().getCurrentBandwidthQuality();
    int[] itags = new int[]{22, 18, 36, 17};

    if (connectionQuality != null && connectionQuality != ConnectionQuality.UNKNOWN) {
        switch (connectionQuality) {
            case POOR:
                itags = new int[]{17, 36, 18, 22};
                break;
            case MODERATE:
                itags = new int[]{36, 18, 22, 17};
                break;
            case GOOD:
            case EXCELLENT:
                itags = new int[]{22, 18, 36, 17};
                break;
        }
    }

    if (ytFiles.get(itags[0]) != null) {
        return ytFiles.get(itags[0]);
    } else if (ytFiles.get(itags[1]) != null) {
        return ytFiles.get(itags[1]);
    } else if (ytFiles.get(itags[2]) != null) {
        return ytFiles.get(itags[2]);
    }
    return ytFiles.get(itags[3]);
}
 
开发者ID:pawelpaszki,项目名称:youtube_background_android,代码行数:35,代码来源:BackgroundAudioService.java

示例5: getYoutubeDownloadUrl

import at.huber.youtubeExtractor.YtFile; //导入依赖的package包/类
private void getYoutubeDownloadUrl(String youtubeLink)
{
    new YouTubeExtractor(this)
    {
        @Override
        public void onExtractionComplete(SparseArray<YtFile> ytFiles, VideoMeta vMeta)
        {
            mainProgressBar.setVisibility(View.GONE);
            if (ytFiles == null) {
                TextView tv = new TextView(getActivityContext());
                tv.setText(R.string.app_update);
                tv.setMovementMethod(LinkMovementMethod.getInstance());
                mainLayout.addView(tv);
                return;
            }
            formatsToShowList = new ArrayList<>();
            for (int i = 0, itag; i < ytFiles.size(); i++) {
                itag = ytFiles.keyAt(i);
                YtFile ytFile = ytFiles.get(itag);

                if (ytFile.getFormat().getHeight() == -1 || ytFile.getFormat().getHeight() >= 360) {
                    addFormatToList(ytFile, ytFiles);
                }
            }
            Collections.sort(formatsToShowList, new Comparator<YouTubeFragmentedVideo>()
            {
                @Override
                public int compare(YouTubeFragmentedVideo lhs, YouTubeFragmentedVideo rhs)
                {
                    return lhs.height - rhs.height;
                }
            });
            for (YouTubeFragmentedVideo files : formatsToShowList) {
                addButtonToMainLayout(vMeta.getTitle(), files);
            }
        }
    }.extract(youtubeLink, true, false);
}
 
开发者ID:teocci,项目名称:YouTube-In-Background,代码行数:39,代码来源:DownloadSharedLinkActivity.java

示例6: getBestStream

import at.huber.youtubeExtractor.YtFile; //导入依赖的package包/类
/**
 * Get the best available audio stream
 *
 * @param ytFiles Array of available streams
 * @return Audio stream with highest bitrate
 */
private YtFile getBestStream(SparseArray<YtFile> ytFiles)
{
    Log.e(TAG, "ytFiles: " + ytFiles);
    if (ytFiles.get(YOUTUBE_ITAG_141) != null) {
        LogHelper.e(TAG, " gets YOUTUBE_ITAG_141");
        return ytFiles.get(YOUTUBE_ITAG_141);
    } else if (ytFiles.get(YOUTUBE_ITAG_140) != null) {
        LogHelper.e(TAG, " gets YOUTUBE_ITAG_140");
        return ytFiles.get(YOUTUBE_ITAG_140);
    } else if (ytFiles.get(YOUTUBE_ITAG_251) != null) {
        LogHelper.e(TAG, " gets YOUTUBE_ITAG_251");
        return ytFiles.get(YOUTUBE_ITAG_251);
    } else if (ytFiles.get(YOUTUBE_ITAG_250) != null) {
        LogHelper.e(TAG, " gets YOUTUBE_ITAG_250");
        return ytFiles.get(YOUTUBE_ITAG_250);
    } else if (ytFiles.get(YOUTUBE_ITAG_249) != null) {
        LogHelper.e(TAG, " gets YOUTUBE_ITAG_249");
        return ytFiles.get(YOUTUBE_ITAG_249);
    } else if (ytFiles.get(YOUTUBE_ITAG_171) != null) {
        LogHelper.e(TAG, " gets YOUTUBE_ITAG_171");
        return ytFiles.get(YOUTUBE_ITAG_171);
    } else if (ytFiles.get(YOUTUBE_ITAG_18) != null) {
        LogHelper.e(TAG, " gets YOUTUBE_ITAG_18");
        return ytFiles.get(YOUTUBE_ITAG_18);
    } else if (ytFiles.get(YOUTUBE_ITAG_22) != null) {
        LogHelper.e(TAG, " gets YOUTUBE_ITAG_22");
        return ytFiles.get(YOUTUBE_ITAG_22);
    } else if (ytFiles.get(YOUTUBE_ITAG_43) != null) {
        LogHelper.e(TAG, " gets YOUTUBE_ITAG_43");
        return ytFiles.get(YOUTUBE_ITAG_43);
    } else if (ytFiles.get(YOUTUBE_ITAG_36) != null) {
        LogHelper.e(TAG, " gets YOUTUBE_ITAG_36");
        return ytFiles.get(YOUTUBE_ITAG_36);
    }

    LogHelper.e(TAG, " gets YOUTUBE_ITAG_17");
    return ytFiles.get(YOUTUBE_ITAG_17);
}
 
开发者ID:teocci,项目名称:YouTube-In-Background,代码行数:45,代码来源:BackgroundAudioService.java

示例7: getBestStream

import at.huber.youtubeExtractor.YtFile; //导入依赖的package包/类
/**
     * Get the best available audio stream
     *
     * @param ytFiles Array of available streams
     * @return Audio stream with highest bitrate
     */
    private YtFile getBestStream(SparseArray<YtFile> ytFiles)
    {
//        Log.e(TAG, "ytFiles: " + ytFiles);
        if (ytFiles.get(YOUTUBE_ITAG_141) != null) {
            LogHelper.e(TAG, " gets YOUTUBE_ITAG_141");
            return ytFiles.get(YOUTUBE_ITAG_141);
        } else if (ytFiles.get(YOUTUBE_ITAG_140) != null) {
            LogHelper.e(TAG, " gets YOUTUBE_ITAG_140");
            return ytFiles.get(YOUTUBE_ITAG_140);
        } else if (ytFiles.get(YOUTUBE_ITAG_251) != null) {
            LogHelper.e(TAG, " gets YOUTUBE_ITAG_251");
            return ytFiles.get(YOUTUBE_ITAG_251);
        } else if (ytFiles.get(YOUTUBE_ITAG_250) != null) {
            LogHelper.e(TAG, " gets YOUTUBE_ITAG_250");
            return ytFiles.get(YOUTUBE_ITAG_250);
        } else if (ytFiles.get(YOUTUBE_ITAG_249) != null) {
            LogHelper.e(TAG, " gets YOUTUBE_ITAG_249");
            return ytFiles.get(YOUTUBE_ITAG_249);
        } else if (ytFiles.get(YOUTUBE_ITAG_171) != null) {
            LogHelper.e(TAG, " gets YOUTUBE_ITAG_171");
            return ytFiles.get(YOUTUBE_ITAG_171);
        } else if (ytFiles.get(YOUTUBE_ITAG_18) != null) {
            LogHelper.e(TAG, " gets YOUTUBE_ITAG_18");
            return ytFiles.get(YOUTUBE_ITAG_18);
        } else if (ytFiles.get(YOUTUBE_ITAG_22) != null) {
            LogHelper.e(TAG, " gets YOUTUBE_ITAG_22");
            return ytFiles.get(YOUTUBE_ITAG_22);
        } else if (ytFiles.get(YOUTUBE_ITAG_43) != null) {
            LogHelper.e(TAG, " gets YOUTUBE_ITAG_43");
            return ytFiles.get(YOUTUBE_ITAG_43);
        } else if (ytFiles.get(YOUTUBE_ITAG_36) != null) {
            LogHelper.e(TAG, " gets YOUTUBE_ITAG_36");
            return ytFiles.get(YOUTUBE_ITAG_36);
        }

        LogHelper.e(TAG, " gets YOUTUBE_ITAG_17");
        return ytFiles.get(YOUTUBE_ITAG_17);
    }
 
开发者ID:teocci,项目名称:YouTube-In-Background,代码行数:45,代码来源:LocalPlayback.java

示例8: getBestStream

import at.huber.youtubeExtractor.YtFile; //导入依赖的package包/类
/**
 * Get the best available audio stream
 * <p>
 * Itags:
 * 141 - mp4a - stereo, 44.1 KHz 256 Kbps
 * 251 - webm - stereo, 48 KHz 160 Kbps
 * 140 - mp4a - stereo, 44.1 KHz 128 Kbps
 * 17 - mp4 - stereo, 44.1 KHz 96-100 Kbps
 *
 * @param ytFiles Array of available streams
 * @return Audio stream with highest bitrate
 */
private YtFile getBestStream(SparseArray<YtFile> ytFiles) {

    connectionQuality = ConnectionClassManager.getInstance().getCurrentBandwidthQuality();
    int[] itags = new int[]{251, 141, 140, 17};

    if (connectionQuality != null && connectionQuality != ConnectionQuality.UNKNOWN) {
        switch (connectionQuality) {
            case POOR:
                itags = new int[]{17, 140, 251, 141};
                break;
            case MODERATE:
                itags = new int[]{251, 141, 140, 17};
                break;
            case GOOD:
            case EXCELLENT:
                itags = new int[]{141, 251, 140, 17};
                break;
        }
    }

    if (ytFiles.get(itags[0]) != null) {
        return ytFiles.get(itags[0]);
    } else if (ytFiles.get(itags[1]) != null) {
        return ytFiles.get(itags[1]);
    } else if (ytFiles.get(itags[2]) != null) {
        return ytFiles.get(itags[2]);
    }
    return ytFiles.get(itags[3]);
}
 
开发者ID:smedic,项目名称:Android-YouTube-Background-Player,代码行数:42,代码来源:BackgroundAudioService.java

示例9: extractUrlAndPlay

import at.huber.youtubeExtractor.YtFile; //导入依赖的package包/类
/**
 * Extracts link from youtube video ID, so mediaPlayer can play it
 */
private void extractUrlAndPlay() {
    String youtubeLink = Config.YOUTUBE_BASE_URL + videoItem.getId();
    deviceBandwidthSampler.startSampling();

    new YouTubeExtractor(this) {
        @Override
        protected void onExtractionComplete(SparseArray<YtFile> ytFiles, VideoMeta videoMeta) {
            if (ytFiles == null) {
                // Something went wrong we got no urls. Always check this.
                Toast.makeText(YTApplication.getAppContext(), R.string.failed_playback,
                        Toast.LENGTH_SHORT).show();
                return;
            }
            deviceBandwidthSampler.stopSampling();
            YtFile ytFile = getBestStream(ytFiles);
            try {
                if (mMediaPlayer != null) {
                    mMediaPlayer.reset();
                    mMediaPlayer.setDataSource(ytFile.getUrl());
                    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                    mMediaPlayer.prepare();
                    mMediaPlayer.start();

                    Toast.makeText(YTApplication.getAppContext(), videoItem.getTitle(), Toast.LENGTH_SHORT).show();
                }
            } catch (IOException io) {
                io.printStackTrace();
            }
        }
    }.execute(youtubeLink);
}
 
开发者ID:smedic,项目名称:Android-YouTube-Background-Player,代码行数:35,代码来源:BackgroundAudioService.java

示例10: startParsing

import at.huber.youtubeExtractor.YtFile; //导入依赖的package包/类
public static void startParsing(final Context context, String param, final Invokable<Video, Integer> invokable) {
    YouTubeExtractor mYoutubeExtractor = new YouTubeExtractor(context) {
        @Override
        public void onExtractionComplete(SparseArray<YtFile> ytFiles, VideoMeta vMeta) {
            if (ytFiles != null) {
                YoutubeVideo video = new YoutubeVideo(vMeta.getTitle(), vMeta.getVideoId());
                for(Pair p : YoutubeVideo.itagQualityMapping) {
                    YtFile videoFormat = ytFiles.get(Integer.parseInt(p.first.toString()));
                    if (videoFormat == null) {
                        continue;
                    }
                    video.addFormat(videoFormat.getUrl(), Integer.parseInt(p.first.toString()));
                }

                try {
                    invokable.invoke(video);
                } catch (java.lang.Exception e) {
                    FirebaseCrash.report(e);
                    e.printStackTrace();
                }
            } else {
                Log.e(TAG, "URLs are empty");
            }
        }
    };

    Log.v(TAG, YOUTUBE_URL_PREFIX + param);
    mYoutubeExtractor.extract(YOUTUBE_URL_PREFIX + param, false, true);
}
 
开发者ID:Ashish-Bansal,项目名称:OneTapVideoDownload,代码行数:30,代码来源:YoutubeParserProxy.java

示例11: onClick

import at.huber.youtubeExtractor.YtFile; //导入依赖的package包/类
@Override
        public void onClick(View v) {
            if (post.getVideoUrl().contains("youtube") || post.getVideoUrl().contains("youtu.be")) {
                YoutubeManager.getInstance().startParseYoutubeUrl((Activity) getContext(), post.getVideoUrl(), new OnYoutubeParseListener() {
                    @Override
                    public int describeContents() {
                        return 0;
                    }

                    @Override
                    public void writeToParcel(Parcel dest, int flags) {

                    }

                    @Override
                    public void onUrisAvailable(String videoId, String videoTitle, SparseArray<YtFile> ytFiles) {
                        KLog.v(TAG, "onYoutube id: " + videoId);
                        KLog.v(TAG, "onYoutube title: " + videoTitle);
                        if (ytFiles == null) {
                            Toast.makeText(getContext(), "此影片目前無法觀看", Toast.LENGTH_LONG).show();
                            return;
                        }
//                            KLog.v(TAG, "onYoutube files: " + ytFiles.size() + "_" + ytFiles.get(22).getUrl());
                        int index = ytFiles.size() > 1 ? 1 : 0;
                        KomicaManager.getInstance().startPlayerActivity(getContext(), videoTitle, ytFiles.get(ytFiles.keyAt(index)).getUrl());
                    }
                });
            } else {
                KomicaManager.getInstance().startPlayerActivity(v.getContext(), post.getTitle(), post.getVideoUrl());
            }
        }
 
开发者ID:TakumaMochizuki,项目名称:Komica,代码行数:32,代码来源:PostView.java

示例12: startPlayer

import at.huber.youtubeExtractor.YtFile; //导入依赖的package包/类
private void startPlayer(Context context, String videoTitle, SparseArray<YtFile> ytFiles) {
        if (ytFiles == null) {
            Toast.makeText(context, "此影片目前無法觀看", Toast.LENGTH_LONG).show();
            return;
        }
//                            KLog.v(TAG, "onYoutube files: " + ytFiles.size() + "_" + ytFiles.get(22).getUrl());
        int index = ytFiles.size() > 1 ? 1 : 0;
        KomicaManager.getInstance().startPlayerActivity(context, videoTitle, ytFiles.get(ytFiles.keyAt(index)).getUrl());
    }
 
开发者ID:TakumaMochizuki,项目名称:Komica,代码行数:10,代码来源:YoutubeManager.java

示例13: downloadVideo

import at.huber.youtubeExtractor.YtFile; //导入依赖的package包/类
static void downloadVideo(final YouTubeVideo video, final Context context, final Config.MediaType type) {
    String youtubeLink = Config.YOUTUBE_BASE_URL + video.getId();
    new YouTubeExtractor(context) {

        @Override
        public void onExtractionComplete(SparseArray<YtFile> ytFiles, VideoMeta vMeta) {

            if (ytFiles == null) {
                return;
            }
            ArrayList <Integer> iTags = new ArrayList<>();

            for (int i = 0, itag; i < ytFiles.size(); i++) {
                itag = ytFiles.keyAt(i);
                    iTags.add(itag);
            }
            YtFile ytFile;
            int index;
            if(type.equals(Config.MediaType.VIDEO)) {
                if(iTags.contains(22)) {
                    ytFile = ytFiles.get(22);
                    index = 22;
                } else if(iTags.contains(18)) {
                    ytFile = ytFiles.get(18);
                    index = 18;
                } else if(iTags.contains(36)) {
                    ytFile = ytFiles.get(36);
                    index = 36;
                } else if(iTags.contains(17)) {
                    ytFile = ytFiles.get(17);
                    index = 17;
                } else {
                    ytFile = ytFiles.get(ytFiles.size() - 1);
                    index = ytFiles.keyAt(ytFiles.size() - 1);
                }
            } else {
                if(iTags.contains(251)) {
                    ytFile = ytFiles.get(251);
                    index = 251;
                } else if(iTags.contains(140)) {
                    ytFile = ytFiles.get(140);
                    index = 140;
                } else if(iTags.contains(171)) {
                    ytFile = ytFiles.get(171);
                    index = 171;
                } else if(iTags.contains(250)) {
                    ytFile = ytFiles.get(250);
                    index = 250;
                } else if(iTags.contains(249)) {
                    ytFile = ytFiles.get(249);
                    index = 249;
                } else if(iTags.contains(139)) {
                    ytFile = ytFiles.get(139);
                    index = 139;
                } else {
                    Toast.makeText(YTApplication.getAppContext(), "No audio file available",
                            Toast.LENGTH_SHORT).show();
                    return;
                }
            }
            String filename = video.getId() + "." + ytFile.getFormat().getExt();
            downloadFromUrl(ytFile.getUrl(), video.getTitle(), filename, context, video.getId());
        }
    }.extract(youtubeLink, true, false);
}
 
开发者ID:pawelpaszki,项目名称:youtube_background_android,代码行数:66,代码来源:MediaStorageHandler.java

示例14: newExtractUrlAndPlay

import at.huber.youtubeExtractor.YtFile; //导入依赖的package包/类
/**
     * Extracts link from youtube video ID, so mediaPlayer can play it
     */
    private void newExtractUrlAndPlay()
    {
//        LogHelper.e(TAG, "extractUrlAndPlay: extracting url for video id=" + currentVideo.getId());
        final String youtubeLink = "https://youtube.com/watch?v=" + currentVideo.getId();
//        LogHelper.e(TAG, youtubeLink);

        new YouTubeExtractor(this)
        {
            @Override
            public void onExtractionComplete(SparseArray<YtFile> ytFiles, VideoMeta videoMeta)
            {
                if (ytFiles == null) {
                    Toast.makeText(
                            getApplicationContext(),
                            getResources().getString(R.string.toast_message_error_extracting, videoMeta.getTitle()),
                            Toast.LENGTH_SHORT
                    ).show();
                    return;
                }

                if (ytFiles != null) {
                    YtFile ytFile = getBestStream(ytFiles);
                    LogHelper.e(TAG, ytFile.getUrl());
                    if (ytFile != null && validateUrl(ytFile.getUrl())) {
                        playOnFocusGain = true;
                        currentPosition = 0;
                        tryToGetAudioFocus();
                        registerAudioNoisyReceiver();
                        registerMediaButtonReceiver();
                        playState = PlaybackStateCompat.STATE_STOPPED;
                        relaxResources(false); // release everything except MediaPlayer

                        try {
//                            LogHelper.e(TAG, "extractUrlAndPlay: Start playback");

                            createMediaPlayerIfNeeded();

                            playState = PlaybackStateCompat.STATE_BUFFERING;

                            mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                            mediaPlayer.setDataSource(ytFile.getUrl());
                            mediaPlayer.setOnPreparedListener(backgroundAudioService);
                            currentVideoTitle = videoMeta.getTitle();

                            // Starts preparing the media player in the background. When
                            // it's done, it will call our OnPreparedListener (that is,
                            // the onPrepared() method on this class, since we set the
                            // listener to 'this'). Until the media player is prepared,
                            // we *cannot* call start() on it!
                            mediaPlayer.prepareAsync();

                            // If we are streaming from the internet, we want to hold a
                            // Wifi lock, which prevents the Wifi radio from going to
                            // sleep while the song is playing.
                            wifiLock.acquire();
                        } catch (IOException io) {
//                            LogHelper.e(TAG, io, "extractUrlAndPlay: Exception playing song");
                            io.printStackTrace();
                        }
                    } else {
//                        Log.e(TAG, "No Link found");
                        Toast.makeText(
                                getApplicationContext(),
                                getResources().getString(R.string.toast_message_error_playing_url, videoMeta.getTitle()),
                                Toast.LENGTH_SHORT
                        ).show();
                    }
                }
            }
        }.extract(youtubeLink, true, true);
    }
 
开发者ID:teocci,项目名称:YouTube-In-Background,代码行数:75,代码来源:BackgroundAudioService.java

示例15: extractUrlAndPlay

import at.huber.youtubeExtractor.YtFile; //导入依赖的package包/类
/**
     * Extracts link from youtube video ID, so mediaPlayer can play it
     */
    private void extractUrlAndPlay()
    {
//        LogHelper.e(TAG, "extractUrlAndPlay: extracting url for video id=" + currentVideo.getId());
        final String youtubeLink = "http://youtube.com/watch?v=" + currentVideo.getId();
//        LogHelper.e(TAG, youtubeLink);

        YouTubeUriExtractor ytEx = new YouTubeUriExtractor(this)
        {
            @Override
            public void onUrisAvailable(String videoId, final String videoTitle,
                                        SparseArray<YtFile> ytFiles)
            {
                if (ytFiles != null) {
                    YtFile ytFile = getBestStream(ytFiles);

                    playOnFocusGain = true;
                    currentPosition = 0;
                    tryToGetAudioFocus();
                    registerAudioNoisyReceiver();
                    playState = PlaybackStateCompat.STATE_STOPPED;
                    relaxResources(false); // Release everything except MediaPlayer

                    try {
//                        LogHelper.e(TAG, ytFile.getUrl());
//                        LogHelper.e(TAG, "extractUrlAndPlay: Start playback");

                        createMediaPlayerIfNeeded();

                        playState = PlaybackStateCompat.STATE_BUFFERING;

                        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                        mediaPlayer.setDataSource(ytFile.getUrl());
                        mediaPlayer.setOnPreparedListener(backgroundAudioService);
                        currentVideoTitle = videoTitle;

                        // Starts preparing the media player in the background. When
                        // it's done, it will call our OnPreparedListener (that is,
                        // the onPrepared() method on this class, since we set the
                        // listener to 'this'). Until the media player is prepared,
                        // we *cannot* call start() on it!
                        mediaPlayer.prepareAsync();

                        // If we are streaming from the internet, we want to hold a
                        // Wifi lock, which prevents the Wifi radio from going to
                        // sleep while the song is playing.
                        wifiLock.acquire();
//                            mediaPlayer.start();

//                        if (callback != null) {
//                            callback.onPlaybackStatusChanged(playState);
//                        }
                    } catch (IOException io) {
//                        LogHelper.e(TAG, io, "extractUrlAndPlay: Exception playing song");
                        io.printStackTrace();
                    }
                }
            }
        };
        // Ignore the webm container formatViewCount
//         ytEx.setIncludeWebM(false);
//         ytEx.setParseDashManifest(true);
        // Lets execute the request
        ytEx.execute(youtubeLink);
    }
 
开发者ID:teocci,项目名称:YouTube-In-Background,代码行数:68,代码来源:BackgroundAudioService.java


注:本文中的at.huber.youtubeExtractor.YtFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。