2017-12-27 36 views
1

내 앱에서 라이브 스트리밍을 위해 ExoPlayer로 비디오보기를 바꾸려고합니다.Exoplayer v2, 실시간 비디오 스트림

내 코드를 videoView.setVideoURI("")으로 바꾸고 ExoPlayer에서 예제를 찾지 못하고 라이브 비디오를 구현했습니다.

누구든지 구현할 수 있습니까?

감사

+0

https://google.github.io/ExoPlayer/guide.html#getting-started – pskink

답변

0

가 우는 소리 당신의 Gradle을에 컴파일 추가

//Video Playback library 
compile 'com.google.android.exoplayer:exoplayer:r2.5.+' 

는 XML 파일에 선 아래 추가

<com.google.android.exoplayer2.ui.SimpleExoPlayerView 
     android:id="@+id/video_player" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:resize_mode="fill"></com.google.android.exoplayer2.ui.SimpleExoPlayerView> 

쓰기 celow 코드를 사용자의 활동에 :

private SimpleExoPlayer player; 
    private TrackSelector trackSelector; 
    // replace URL with your url/path 
    private String urlToPlay; 

    //I have used butterknife you can bind view as per your convinience 
    @BindView(R.id.video_player) 
    SimpleExoPlayerView feedVideo; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setUpVideo(); 
    } 
    private void setUpVideo() { 
     // 1. Create a default TrackSelector 
     BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); 
     TrackSelection.Factory videoTrackSelectionFactory = 
       new AdaptiveTrackSelection.Factory(bandwidthMeter); 
     trackSelector = new 
     DefaultTrackSelector(videoTrackSelectionFactory); 

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

     feedVideo.setPlayer(player); 
     setUpVideoData(); 
    } 

private void setUpVideoData() { 
     // Measures bandwidth during playback. Can be null if not required. 
     DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); 
     // Produces DataSource instances through which media data is loaded. 
     DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, 
       Util.getUserAgent(this, "yourApplicationName"), bandwidthMeter); 
     // Produces Extractor instances for parsing the media data. 
     ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); 
     // This is the MediaSource representing the media to be played. 
     MediaSource videoSource = new ExtractorMediaSource(Uri.parse(urlToPlay), 
       dataSourceFactory, extractorsFactory, null, null); 
     // Prepare the player with the source. 
     player.prepare(videoSource); 

     // Auto Play video as soon as it buffers 
     player.setPlayWhenReady(true); 
    } 

    @Override 
    public void onPause() { 
     super.onPause(); 
     pauseLivePreview(); 
    } 

    @Override 
    public void onResume() { 
     super.onResume(); 
     resumeLivePreview(); 
    } 

    private void resumeLivePreview() { 
     if (player != null) { 
      player.setPlayWhenReady(true); 
     } 
    } 

    private void pauseLivePreview() { 
     if (player != null) { 
     if (feedVideo != null && feedVideo.getPlayer() != null) { 
      feedVideo.getPlayer().release(); 
     } 
    } 

Refrences https://github.com/google/ExoPlayer https://google.github.io/ExoPlayer/guide.html

+0

덕분에, 어떻게 이력서를 추구하고 onpause 추가하려면? – Googler

+0

나는 당신이 왜 당신이 바 onpause와 이력서를 찾아야 할 필요가 있는지 정교하게 만들어 줄 수 없게했다. –