2016-08-11 6 views
0

캐스트를 연결 해제하기 전에 현재 재생 미디어를 VideoCastManager에서 가져올 수 있습니까?캐스트를 연결 해제하기 전에 미디어의 현재 위치 가져 오기

사용자가 수동으로 캐스트를 끊을 때 현재 미디어의 마지막 진행률을 저장하려고합니다. VideoCastCosumer 메서드 onDisconnected()을 사용했지만 예외가 발생합니다.

System.err: at com.economist.newton.mobile.ui.activity.BaseCastActivity$1.onDisconnected (MyCastActivity.java:81) 

이 줄은 onDisconnected() 방법 내부의 다음 줄을 포함 : 내 로그 만이 보여주기 때문에 예외의 종류를 확실하지

도움이 castManager 변수가 onCreate()에 선언이 경우
try { 
     if(castManager.getCurrentMediaPosition() > 30000){ // <-here error occurs 
       ... 
     } 
} catch (TransientNetworkDisconnectionException | NoConnectionException e) { 
     e.printStackTrace(); 
} 

:

castManager = VideoCastManager.getInstance(); 

캐스트 동반자 라이브러리 : com.google.android.libraries.cast.companionlibrary:ccl:2.8.4

답변

1

이렇게하는 데는 몇 가지 방법이 있습니다. 가장 쉬운 방법은 CCL에서 ProgressWatcher을 구현하는 구성 요소를 사용하는 것입니다. 해당 리스너에서 setProgress(int currentPosition, int duration)이 매 초마다 호출되며 첫 번째 인수로 스트림의 currentPosition을 갖습니다. 이 값을 캐시 할 수 있습니다 (장치가 분리되면 업데이트되지 않습니다). 그러면 현재 위치에 대한 실시간 정보가 제공됩니다. 활동이 인터페이스를 구현한다면, 예를 들면 : 당신이 원하는 때마다

public MyActivity extends AppCompatActivity implements ProgressWatcher { 
    private int mCurrentStreamPosition; 

    public onStart() { 
     .... 
     mCastManager.addProgressWatcher(this); 
     .... 
    } 

    public onStop() { 
     .... 
     mCastManager.removeProgressWatcher(this); 
     .... 
    } 

    public setProgress(int currentTime, int duration) { 
     mCurrentStreamPosition = currentTime; 
    } 

    public int getCurrentStreamPosition() { 
     return mCurrentStreamPosition; 
    } 
    .... 
} 

그래서, 당신은 다음 getCurrentStreamPosition()가 마지막으로/현재의 스트림 위치를 얻기 위해 (예를 들어, 당신이 onDisconnected()에서 호출 할 수 있습니다)을 호출 할 수 있습니다. 앱의 구조에 따라 ProgressWatcheronResume()/onPause() 또는 onCreate()/onDestroy()에 등록/등록 취소 할 수 있습니다. 중요한 것은 메모리 누수를 방지하기 위해 등록을 취소하는 것입니다.

+0

를 얻을 수 있습니다 (CCL 라이브러리없이?)를 –

0

Castv3를 들어, SessionManagerListener에서 onSessionEnding을 무시하고 구글 캐스트 V3와 동일한 달성 할 수있는 가장 쉬운 방법은 무엇 mRemoteMediaClient.getMediaStatus().getStreamPosition()