讀取QOS回放、緩衝和設備統計資訊

您可以從QOSProvider類讀取播放、緩衝和設備統計資訊。

QOSProvider類別提供各種統計資料,包括緩衝、位元速率、影格速率、時間資料等資訊。

此外,它也提供有關裝置的資訊,例如製造商、型號、作業系統、SDK版本、製造商的裝置ID和螢幕大小/密度。

  1. 實例化媒體播放器。

  2. 建立QOSProvider物件,並將它附加至媒體播放器。

    QOSProvider建構函式會擷取播放器內容,以便擷取裝置特定資訊。

    // Create Media Player. 
    _mediaQosProvider = new QOSProvider(getActivity().getApplicationContext()); 
    _mediaQosProvider.attachMediaPlayer(_mediaPlayer);
    
  3. (可選)閱讀播放統計資料。

    讀取播放統計資訊的一個解決方案是具有計時器,該計時器定期從QOSProvider中讀取新的QoS值。 例如:

    _playbackClock = new Clock(PLAYBACK_CLOCK, 1000); // every 1 second 
    
    _playbackClockEventListener = new Clock.ClockEventListener() { 
        @Override 
        public void onTick(String name) { 
            getActivity().runOnUiThread(new Runnable() { 
                @Override 
                public void run() { 
                    PlaybackInformation playbackInformation = _mediaQosProvider.getPlaybackInformation();  
                    setQosItem("Frame rate", (int) playbackInformation.getFrameRate());  
                    setQosItem("Dropped frames", (int) playbackInformation.getDroppedFrameCount()); 
                    setQosItem("Bitrate", (int) playbackInformation.getBitrate()); 
                    setQosItem("Buffering time", (int) playbackInformation.getBufferingTime());  
                    setQosItem("Buffer length", (int) playbackInformation.getBufferLength());  
                    setQosItem("Buffer time", (int) playbackInformation.getBufferTime());  
                    setQosItem("Empty buffer count", (int) playbackInformation.getEmptyBufferCount());  
                    setQosItem("Time to load", (int) playbackInformation.getTimeToLoad());  
                    setQosItem("Time to start", (int) playbackInformation.getTimeToStart()); 
                    setQosItem("Time to prepare", (int) playbackInformation.getTimeToPrepare()); 
                    setQosItem("Perceived Bandwidth", (int) playbackInformation.getPerceivedBandwidth());   
                    playbackInformation.getPerceivedBandwidth()); 
                } 
            }); 
        }; 
    }; 
    
  4. (可選)閱讀裝置特定資訊。

    // Show device information 
    DeviceInformation deviceInfo =  
      new QOSProvider(parent.getApplicationContext()).getDeviceInformation(); 
    tv = (TextView) view.findViewById(R.id.aboutDeviceModel); 
    tv.setText(parent.getString(R.string.aboutDeviceModel) + " " +  
      deviceInfo.getManufacturer() + " - " + deviceInfo.getModel()); 
    
    tv = (TextView) view.findViewById(R.id.aboutDeviceSoftware); 
    tv.setText(parent.getString(R.string.aboutDeviceSoftware) + " " +  
      deviceInfo.getOS() + ", SDK: " + deviceInfo.getSDK()); 
    
    tv = (TextView) view.findViewById(R.id.aboutDeviceResolutin); 
    String orientation = parent.getResources().getConfiguration().orientation ==  
      Configuration.ORIENTATION_LANDSCAPE ? "landscape" : "portrait"; 
    tv.setText(parent.getString(R.string.aboutDeviceResolution) + " " +  
      deviceInfo.getWidthPixels() + "x" + deviceInfo.getHeightPixels() +  
      " (" + orientation + ")"); 
    

本頁內容