È possibile leggere le statistiche di riproduzione, buffering e dispositivo dalla classe QOSProvider.
Il QOSProvider
class fornisce varie statistiche, tra cui informazioni su buffering, bit rate, frame rate, dati temporali e così via.
Fornisce inoltre informazioni sul dispositivo, ad esempio produttore, modello, sistema operativo, versione SDK, ID dispositivo del produttore e dimensioni/densità dello schermo.
Crea un'istanza di un lettore multimediale.
Creare un QOSProvider
e collegarlo al lettore multimediale.
Il QOSProvider
Il costruttore considera un contesto del lettore in modo da poter recuperare informazioni specifiche per il dispositivo.
// Create Media Player.
_mediaQosProvider = new QOSProvider(getActivity().getApplicationContext());
_mediaQosProvider.attachMediaPlayer(_mediaPlayer);
(Facoltativo) Leggi le statistiche di riproduzione.
Una soluzione per leggere le statistiche di riproduzione è disporre di un timer, che recupera periodicamente i nuovi valori QoS dalla QOSProvider
. Ad esempio:
_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());
}
});
};
};
(Facoltativo) Leggi le informazioni specifiche del dispositivo.
// 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 + ")");