當前位置: 首頁>>代碼示例>>Java>>正文


Java ExoPlayerFactory.newSimpleInstance方法代碼示例

本文整理匯總了Java中com.google.android.exoplayer2.ExoPlayerFactory.newSimpleInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java ExoPlayerFactory.newSimpleInstance方法的具體用法?Java ExoPlayerFactory.newSimpleInstance怎麽用?Java ExoPlayerFactory.newSimpleInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.android.exoplayer2.ExoPlayerFactory的用法示例。


在下文中一共展示了ExoPlayerFactory.newSimpleInstance方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onCreate

import com.google.android.exoplayer2.ExoPlayerFactory; //導入方法依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_DEFAULT_CHANNEL_ID, getString(R.string.notification_channel_name), NotificationManagerCompat.IMPORTANCE_DEFAULT);
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.createNotificationChannel(notificationChannel);

        AudioAttributes audioAttributes = new AudioAttributes.Builder()
                .setUsage(AudioAttributes.USAGE_MEDIA)
                .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
                .build();
        audioFocusRequest = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN)
                .setOnAudioFocusChangeListener(audioFocusChangeListener)
                .setAcceptsDelayedFocusGain(false)
                .setWillPauseWhenDucked(true)
                .setAudioAttributes(audioAttributes)
                .build();
    }

    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    mediaSession = new MediaSessionCompat(this, "PlayerService");
    mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setCallback(mediaSessionCallback);

    Context appContext = getApplicationContext();

    Intent activityIntent = new Intent(appContext, MainActivity.class);
    mediaSession.setSessionActivity(PendingIntent.getActivity(appContext, 0, activityIntent, 0));

    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null, appContext, MediaButtonReceiver.class);
    mediaSession.setMediaButtonReceiver(PendingIntent.getBroadcast(appContext, 0, mediaButtonIntent, 0));

    exoPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this), new DefaultTrackSelector(), new DefaultLoadControl());
    exoPlayer.addListener(exoPlayerListener);
    DataSource.Factory httpDataSourceFactory = new OkHttpDataSourceFactory(new OkHttpClient(), Util.getUserAgent(this, getString(R.string.app_name)), null);
    Cache cache = new SimpleCache(new File(this.getCacheDir().getAbsolutePath() + "/exoplayer"), new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 100)); // 100 Mb max
    this.dataSourceFactory = new CacheDataSourceFactory(cache, httpDataSourceFactory, CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR);
    this.extractorsFactory = new DefaultExtractorsFactory();
}
 
開發者ID:SergeyVinyar,項目名稱:AndroidAudioExample,代碼行數:43,代碼來源:PlayerService.java

示例2: createFullPlayer

import com.google.android.exoplayer2.ExoPlayerFactory; //導入方法依賴的package包/類
/***
 * 創建實例播放實例,並不開始緩衝
 **/
private SimpleExoPlayer createFullPlayer() {
    TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter());
    TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
    BufferingLoadControl loadControl = new BufferingLoadControl();
    if (null == modelType) {
        setDefaultLoadModel();
    } else {
        loadControl.setListener(new LoadListener() {
            @Override
            public void onProgress(long pro) {
                getPlayerViewListener().showNetSpeed(String.valueOf(pro) + "%");
            }
        });
    }
    DefaultRenderersFactory rf = new DefaultRenderersFactory(activity, drmSessionManager, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON);
    SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(rf, trackSelector, loadControl);
    player.setPlaybackParameters(playbackParameters);
    getPlayerViewListener().setPlayer(player);
    return player;
}
 
開發者ID:yangchaojiang,項目名稱:yjPlay,代碼行數:24,代碼來源:ExoUserPlayer.java

示例3: setupExoPlayer

import com.google.android.exoplayer2.ExoPlayerFactory; //導入方法依賴的package包/類
private void setupExoPlayer() {
    TrackSelection.Factory adaptiveTrackSelectionFactory =
            new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter());

    exoPlayer = ExoPlayerFactory.newSimpleInstance(
            new DefaultRenderersFactory(this),
            new DefaultTrackSelector(adaptiveTrackSelectionFactory),
            new DefaultLoadControl());
    pvVideoPreview.setPlayer(exoPlayer);
    exoPlayer.setPlayWhenReady(true);

    Uri uri = Uri.parse("asset:///sample_video.mp4");
    MediaSource mediaSource = createMediaSource(this, uri);
    LoopingMediaSource loopingMediaSource = new LoopingMediaSource(mediaSource);
    exoPlayer.prepare(loopingMediaSource, true, false);
}
 
開發者ID:akexorcist,項目名稱:Android-O-Feature,代碼行數:17,代碼來源:PictureInPictureActivity.java

示例4: initExoPlayer

import com.google.android.exoplayer2.ExoPlayerFactory; //導入方法依賴的package包/類
private void initExoPlayer(MediaSource sampleSource) {
  if (exoPlayer == null) {
    TrackSelection.Factory videoTrackSelectionFactory =
        new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter());
    TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

    // 2. Create the player
    exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
  }

  exoPlayer.prepare(sampleSource);

  exoPlayer.setVideoSurfaceView(svPlayer);

  exoPlayer.setPlayWhenReady(true);

  initMediaControls();
}
 
開發者ID:Foso,項目名稱:ExoPlayer-with-MediaControls,代碼行數:19,代碼來源:MainActivity.java

示例5: create

import com.google.android.exoplayer2.ExoPlayerFactory; //導入方法依賴的package包/類
@NonNull
public SimpleExoPlayer create(DrmSessionCreator drmSessionCreator,
                              DefaultDrmSessionManager.EventListener drmSessionEventListener,
                              MediaCodecSelector mediaCodecSelector) {
    DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = drmSessionCreator.create(drmSessionEventListener);
    RenderersFactory renderersFactory = new SimpleRenderersFactory(
            context,
            drmSessionManager,
            EXTENSION_RENDERER_MODE_OFF,
            DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS,
            mediaCodecSelector
    );

    DefaultLoadControl loadControl = new DefaultLoadControl();
    return ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector, loadControl);
}
 
開發者ID:novoda,項目名稱:no-player,代碼行數:17,代碼來源:ExoPlayerCreator.java

示例6: KExoMediaPlayer

import com.google.android.exoplayer2.ExoPlayerFactory; //導入方法依賴的package包/類
public KExoMediaPlayer(Context context) {
    this.context = context.getApplicationContext();

    // [email protected]@=========
    TrackSelection.Factory trackSelectionFactory =
            new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
    DefaultTrackSelector trackSelector = new DefaultTrackSelector(trackSelectionFactory);

    player = ExoPlayerFactory.newSimpleInstance(this.context, trackSelector, new DefaultLoadControl(),
            null);
    player.addListener(eventLogger);
    player.addListener(playerListener);
    player.setVideoListener(playerListener);
    player.setPlayWhenReady(false);

    mainHandler = new Handler();
    userAgent = Util.getUserAgent(this.context, "KExoMediaPlayer");
    mediaDataSourceFactory = new DefaultDataSourceFactory(this.context, userAgent, BANDWIDTH_METER);
}
 
開發者ID:jcodeing,項目名稱:K-Sonic,代碼行數:20,代碼來源:KExoMediaPlayer.java

示例7: loadVideo

import com.google.android.exoplayer2.ExoPlayerFactory; //導入方法依賴的package包/類
public void loadVideo(){
//        CommonTools.showErrorLog("test"+"11111111111");
//        CommonTools.showErrorLog("test"+playerPosition);
        if (player == null){
            TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(BANDWIDTH_METER);
            trackSelector = new DefaultTrackSelector(mainHandler, videoTrackSelectionFactory);
            player = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, new DefaultLoadControl(), null, false);
            player.addListener(this);
            setPlayer(player);
//            CommonTools.showErrorLog("test"+"222222222");
            if (playerPosition > 0){
//                CommonTools.showErrorLog("test"+"3333333333");
                player.seekTo(playerPosition);
            }
            player.setPlayWhenReady(isAutoPlay);
        }
        if (uri == null){
//            CommonTools.showToast(getContext(), "請選擇一個視頻來播放");
            return;
        }
        MediaSource mediaSource = buildMediaSource(uri, null);
        player.prepare(mediaSource);
    }
 
開發者ID:zhanglibin123488,項目名稱:videoPickPlayer,代碼行數:24,代碼來源:CustomExoPlayerView.java

示例8: initializePlayer

import com.google.android.exoplayer2.ExoPlayerFactory; //導入方法依賴的package包/類
private void initializePlayer() {
    simpleExoPlayerView.requestFocus();
    TrackSelection.Factory videoTrackSelectionFactory =
            new AdaptiveTrackSelection.Factory(bandwidthMeter);
    trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
    player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
    simpleExoPlayerView.setPlayer(player);

    MediaSource[] mediaSources = new MediaSource[videos.size()];
    for (int i = 0; i < videos.size(); i++) {
        mediaSources[i] = buildMediaSource(Uri.parse(videos.get(i).videoUrl));
    }
    MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0]
            : new ConcatenatingMediaSource(mediaSources);
    player.prepare(mediaSource);
}
 
開發者ID:yusufcakmak,項目名稱:ExoPlayerSample,代碼行數:17,代碼來源:PlayListActivity.java

示例9: initializePlayer

import com.google.android.exoplayer2.ExoPlayerFactory; //導入方法依賴的package包/類
private void initializePlayer() {
    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory videoTrackSelectionFactory =
            new AdaptiveTrackSelection.Factory(bandwidthMeter);
    mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

    mPlayer = ExoPlayerFactory.newSimpleInstance(getActivity(), mTrackSelector);
    mPlayerAdapter = new LeanbackPlayerAdapter(getActivity(), mPlayer, UPDATE_DELAY);
    mPlaylistActionListener = new PlaylistActionListener(mPlaylist);
    mPlayerGlue = new VideoPlayerGlue(getActivity(), mPlayerAdapter, mPlaylistActionListener);
    mPlayerGlue.setHost(new VideoFragmentGlueHost(this));
    mPlayerGlue.playWhenPrepared();

    play(mVideo);

    ArrayObjectAdapter mRowsAdapter = initializeRelatedVideosRow();
    setAdapter(mRowsAdapter);
}
 
開發者ID:googlesamples,項目名稱:androidtv-Leanback,代碼行數:19,代碼來源:PlaybackFragment.java

示例10: setUpExoPlayer

import com.google.android.exoplayer2.ExoPlayerFactory; //導入方法依賴的package包/類
private void setUpExoPlayer() {
    // Create a default TrackSelector
    TrackSelector trackSelector = createTrackSelector();

    // Create a default LoadControl
    LoadControl loadControl = new DefaultLoadControl();

    // Create the player
    exoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl);
    resumeLocalVideo();

    exoPlayer.addListener(exoPlayerEventListener);
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:14,代碼來源:VideoDetailsFragment.java

示例11: PlayerController

import com.google.android.exoplayer2.ExoPlayerFactory; //導入方法依賴的package包/類
public PlayerController(Context context) {
    this.bandwidthMeter = new DefaultBandwidthMeter();
    this.loadControl = new DefaultLoadControl();
    this.extractorsFactory = new DefaultExtractorsFactory();
    this.trackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
    this.dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context.getApplicationContext(), TAG_NAME), (TransferListener<? super DataSource>) bandwidthMeter);
    this.trackSelector = new DefaultTrackSelector(trackSelectionFactory);
    this.player = ExoPlayerFactory.newSimpleInstance(context, this.trackSelector, this.loadControl);
    this.playerView = new PlayerView(context,this.player);
}
 
開發者ID:herudi,項目名稱:react-native-exoplayer-intent-video,代碼行數:11,代碼來源:PlayerController.java

示例12: initExoPlayer

import com.google.android.exoplayer2.ExoPlayerFactory; //導入方法依賴的package包/類
private void initExoPlayer() {
    DefaultBandwidthMeter bwMeter = new DefaultBandwidthMeter();
    AdaptiveTrackSelection.Factory trackFactory = new AdaptiveTrackSelection.Factory(bwMeter);
    DefaultTrackSelector trackSelector = new DefaultTrackSelector(trackFactory);
    player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
    videoView.setPlayer(player);

    DataSource.Factory dsFactory = new DefaultDataSourceFactory(getBaseContext(),
            Util.getUserAgent(this, "Traxy"), bwMeter);
    ExtractorsFactory exFactory = new DefaultExtractorsFactory();
    Uri mediaUri = Uri.parse(entry.getUrl());
    MediaSource videoSource = new ExtractorMediaSource(mediaUri,
            dsFactory, exFactory, null, null);
    player.prepare(videoSource);
}
 
開發者ID:gvsucis,項目名稱:mobile-app-dev-book,代碼行數:16,代碼來源:MediaViewActivity.java

示例13: createPlayer

import com.google.android.exoplayer2.ExoPlayerFactory; //導入方法依賴的package包/類
private static SimpleExoPlayer createPlayer(Context context) {
    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
    TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

    return ExoPlayerFactory.newSimpleInstance(context.getApplicationContext(), trackSelector);
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:8,代碼來源:ExoVideoPlayer.java

示例14: createFullPlayer

import com.google.android.exoplayer2.ExoPlayerFactory; //導入方法依賴的package包/類
private SimpleExoPlayer createFullPlayer() {
    TrackSelection.Factory videoTrackSelectionFactory
            = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter());
    TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
    LoadControl loadControl = new DefaultLoadControl();
    SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(
            new DefaultRenderersFactory(playerView.getContext()),
            trackSelector, loadControl);
    player.setPlayWhenReady(true);
    player.prepare(mediaSourceBuilder.getMediaSource(false));
    player.addListener(eventListener);
    return player;
}
 
開發者ID:rubensousa,項目名稱:PreviewSeekBar,代碼行數:14,代碼來源:ExoPlayerManager.java

示例15: buildExoPlayer

import com.google.android.exoplayer2.ExoPlayerFactory; //導入方法依賴的package包/類
@SuppressWarnings("unused")
protected SimpleExoPlayer buildExoPlayer(HostActivity host, Surface surface,
    MappingTrackSelector trackSelector,
    DrmSessionManager<FrameworkMediaCrypto> drmSessionManager) {
  SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(host, trackSelector,
      new DefaultLoadControl(), drmSessionManager, SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF,
      0);
  player.setVideoSurface(surface);
  return player;
}
 
開發者ID:ashwanijanghu,項目名稱:ExoPlayer-Offline,代碼行數:11,代碼來源:ExoHostedTest.java


注:本文中的com.google.android.exoplayer2.ExoPlayerFactory.newSimpleInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。