2013-08-14 16 views
5

registerMediaRouteProvider kullanıyorum ve televizyonun ses düzeyini güncelleştirmek için bir birim çubuk verir. MediaRouteAdapter'u uyguladı ve ses çubuğunu temizlediğimde, birim değişir, ancak birim çubuğunun ui'si her zaman 0'a geri döner. Ses düzeyi değiştiğinde ses çubuğunun kullanıcı arayüzünü nasıl güncellerim?MinimalMediaRouteProvider'daki birim çubuğu nasıl güncelleştirilir

@Override 
public void onCreate(Bundle savedInstanceState) { 

    mCastContext = new CastContext(getApplicationContext()); 
    MediaRouteHelper.registerMinimalMediaRouteProvider(mCastContext, this); 
    mMediaRouter = MediaRouter.getInstance(getApplicationContext()); 
    mMediaRouteSelector = MediaRouteHelper.buildMediaRouteSelector(MediaRouteHelper.CATEGORY_CAST); 
    mMetaData = new ContentMetadata(); 

    mMediaRouterCallback = new MyMediaRouterCallback(); 
    mMediaRouteButton.setRouteSelector(mMediaRouteSelector); 
} 

private class MyMediaRouterCallback extends MediaRouter.Callback { 
    @Override 
    public void onRouteSelected(MediaRouter router, RouteInfo route) { 
     MediaRouteHelper.requestCastDeviceForRoute(route); 
    } 

    @Override 
    public void onRouteUnselected(MediaRouter router, RouteInfo route) { 
     try { 
      if (mSession != null) { 
       Log.e(TAG, "Ending session and stopping application"); 
       mSession.setStopApplicationWhenEnding(true); 
       mSession.endSession(); 
      } else { 
       Log.e(TAG, "onRouteUnselected: mSession is null"); 
      } 
     } catch (IllegalStateException e) { 
      Log.e(TAG, "onRouteUnselected:"); 
      e.printStackTrace(); 
     } catch (IOException e) { 
      Log.e(TAG, "onRouteUnselected:"); 
      e.printStackTrace(); 
     } 
     mSelectedDevice = null; 
    } 
} 

@Override 
public void onDeviceAvailable(CastDevice device, String arg1, MediaRouteStateChangeListener listener) { 
    mSelectedDevice = device; 
    openSession(); 
} 

@Override 
public void onSetVolume(double volume) { 
    try { 
     if (mMessageStream != null) { 
      mMessageStream.setVolume(volume); 
     } 
    } catch (IllegalStateException e) { 
     Log.e(TAG, "Problem sending Set Volume", e); 
    } catch (IOException e) { 
     Log.e(TAG, "Problem sending Set Volume", e); 
    } 
} 

@Override 
public void onUpdateVolume(double volumeChange) { 
    try { 
     if (mCurrentRoute != null) { 
      mCurrentRoute.requestUpdateVolume((int) (volumeChange * 20)); 
     } 
    } catch (IllegalStateException e) { 
     Log.e(TAG, "Problem sending Update Volume", e); 
    } 
} 

DÜZENLEME - katma Ben Alıcı düzeyinde mMessageStream

private void openSession() { 
     mSession = new ApplicationSession(mCastContext, mSelectedDevice); 
     int flags = 0; 
     flags |= ApplicationSession.FLAG_DISABLE_NOTIFICATION; 
     flags |= ApplicationSession.FLAG_DISABLE_LOCK_SCREEN_REMOTE_CONTROL; 
     mSession.setApplicationOptions(flags); 

     Log.d(TAG, "Beginning session with context: " + mCastContext); 
     Log.d(TAG, "The session to begin: " + mSession); 
     mSession.setListener(new com.google.cast.ApplicationSession.Listener() { 

      @Override 
      public void onSessionStarted(ApplicationMetadata appMetadata) { 
       Log.d(TAG, "Getting channel after session start"); 
       ApplicationChannel channel = mSession.getChannel(); 
       if (channel == null) { 
        Log.e(TAG, "channel = null"); 
        return; 
       } 
       Log.d(TAG, "Creating and attaching Message Stream"); 
       mMessageStream = new MediaProtocolMessageStream(); 
       channel.attachMessageStream(mMessageStream); 

       if (mMessageStream.getPlayerState() == null) { 
        if (vastVideoView.getPlayingPlaylistItem() != null) { 
         loadMedia(); 
        } 
       } else { 
        Log.e(TAG, "Found player already running; updating status"); 
       } 
      } 

      @Override 
      public void onSessionStartFailed(SessionError error) { 
       Log.e(TAG, "onStartFailed " + error + " code " + error.getCode()); 
       nowifi.setVisibility(View.GONE); 
      } 

      @Override 
      public void onSessionEnded(SessionError error) { 
       Log.i(TAG, "onEnded " + error); 
       controller.removeChromeCastListener(); 
       controller.setChromeCast(false); 
       nowifi.setVisibility(View.GONE); 
      } 
     }); 

     try { 
      Log.e(TAG, "Starting session with app name " + getString(R.string.app_id)); 
      mSession.startSession(getString(R.string.app_id)); 

      vastVideoView.stopPlayback(); 

      controller = vastVideoView.getMediaController(); 
      controller.setChromeCast(true); 
      controller.setPausePlayListener(pausePlayListener); 
      seekBar = controller.getSeekBar(); 
      seekBar.setProgress(0); 

      mPlayButtonShowsPlay = true; 
     } catch (IOException e) { 
      Log.e(TAG, "Failed to open session", e); 
      controller.removeChromeCastListener(); 
      controller.setChromeCast(false); 
      nowifi.setVisibility(View.GONE); 
     } 
    } 

This is the volume bar that is not updating

cevap

1

başlatmak, ses seviyesini ayarlamak için iki yol vardır:

  1. cast.Receiver .Platform.setVolume ([0.0,1.0]) Bu, vo değerini ayarlayacaktır. lume ve mavi çubuğu göster. Bu genellikle onVolume mesajıyla aranır.

  2. mediaElement.volume = [0.0, 1.0]; Bu, mavi çubuğu göstermeden sesi ayarlar. Bunun için soluk/sönük ve eşitleme için kullanabilirsiniz. Java koduna Şimdi üzerinde

: Sana Yayınladığınız şeyle daki messageStream alıyorsanız nasıl, ama doğru bir şey olması muhtemel olduğundan değil.

kamu nihai MediaProtocolCommand setVolume (çift hacmi)

ses düzeyini ayarlar: Burada lines from the reference docs bu. Parametreler volume Birim, 0,0 (% 0) ila 1,0 (% 100) aralığında. döndürür Bu istek için komut nesnesi Atar IOException İleti gönderilirken bir G/Ç hatası oluşursa. IllegalStateException Bu akış bağlı bir kanala bağlı değilse.

+0

. Yukarıdaki kodu ekleyeceğim.Zaten 'onSetVolume' içinde' MediaProcolCommand' 'setVolume' var. Aradığım şey, hacim çubuğunu gösterdiği iletişim kutusu açılır penceresindeki hacim arama çubuğunu nasıl güncelleyeceğiniz ve – heero

4

Günlerdir bu arıyordum ve aniden başıma çözüm buldu:

İlk P Bunu işlemek için bir MediaRouteStateChangeListener gerekecektir.

MediaRouteStateChangeListener mRouteStateListener; 

İkincisi, onDeviceAvailable dinleyiciyi atayın.

@Override 
public void onDeviceAvailable(CastDevice device, String arg1, MediaRouteStateChangeListener listener) { 
    mSelectedDevice = device; 
    mRouteStateListener = listener; 
    openSession(); 
} 

Son onSetVolume veya onUpdateVolume içinde MediaRouteStateListener.onVolumeChanged() diyoruz.

@Override 
public void onSetVolume(double volume) { 
    try { 
     if (mMessageStream != null) { 
      mMessageStream.setVolume(volume); 
      mRouteStateListener.onVolumeChanged(volume); 
     } 
    } catch (IllegalStateException e) { 
     Log.e(TAG, "Problem sending Set Volume", e); 
    } catch (IOException e) { 
     Log.e(TAG, "Problem sending Set Volume", e); 
    } 
} 

Bu, hacim arama çubuğunuzun normal şekilde hareket etmesine yardımcı olur. :)

+0

düğmesinin bağlantısını kestirmenizdir. Çözümünüz android-cast-sample projesinde çalıştı. Ama androidSupport.v7.app.MediaRouteActionProvider değiştirdiğimde "ActionBarSherlock ile kullanmak için MediaRouteButton ile eylem öğeye. Çalışmıyor. ActionProviderClass veya MediaRouteButton kullandınız mı –

0

Google, bu yaz denetimleri, bağlı cihazlar ve uygulamalar arasında paylaşılacak şekilde bu yaz denetimlerini güncelledi. İşte benim çözüm bakın: Ben `ApplicationSession.Listener onSessionStarted` içinde` MediaProtocolMessageStream` nesnesi kuruyorum

https://stackoverflow.com/a/26554007/672373

İlgili konular