Streaming Measurement in Android
This chapter describes the basic use of the sensor for the measurement of streaming content.
Properties of the Library
Property | Default | Description |
---|---|---|
tracking | true | If this property is set to |
debug | false | If the value is set to true , the debug messages are issued by the library |
timeout | 10 | Timeout Setting for the HTTP-Request |
Lifecycle of the Measurement
This chapter explaines step by step the use of the sensor and the measurement of streaming content . The following steps are necessary in order to measure a content.
- Generating the sensor
- Implementation of the adapter
- Beginning of the measurement
- End of the measurement
Generating the Sensor
When you start the app the sensor must be instantiated once. It is not possible to change the site name or the application name after this call.
...
Note |
---|
The site name and application name is specified by the operator of the measurement system. |
Implementation of the Adapter
In principle it is possible to measure any media library with an adapter, that is available within an app to use streaming content .
...
Code Block | ||
---|---|---|
| ||
package de.spring.mobile; /** * This adapter must be used to support some players by the library. * * @see Meta * @see SpringStreams * @see SpringStreams#track(StreamAdapter, java.util.Map) * * @author <a href="mailto:support@spring.de">spring GmbH & Co.KG</a> */ public interface StreamAdapter { public interface Meta { public String getPlayerName(); public String getPlayerVersion(); public int getScreenWidth(); public int getScreenHeight(); } public Meta getMeta(); public int getPosition(); public int getDuration(); public int getWidth(); public int getHeight(); } |
Beginning of the Measurement
This chapter explains step by step how a streaming content is transferred to the library for the measurement.
...
Info |
---|
A stream is measured as long as the Activity is in the foreground. When the Activity goes into the background, the current status is transmitted to the measurement system and the measurement stops. If the stream should be measured again, when the application will come back to the foreground, the method |
End of the Measurement
After the measurement of a stream has been started, this stream is measured by the sensor. The measurement can be stopped by calling the method stop
on the stream object. All measurements will be automatically stopped by the library, when the application goes into the background.
...
Info |
---|
If the stream should be measured again, when the Activity comes to the foreground or after the method |
Ending the application
If the application is closed, the method unload
can be called. This call sends the current state of the measurements to the measuring system and then terminates all measurements. This method is automatically called by the library, when the application goes into the background.
Code Block | ||
---|---|---|
| ||
... sensor.unload(); |
Using the SpringStreamsActivity
In the library is a SpringStreamsActivity included, that can be used to largely automate the measurement. The source code of this class can be found in Appendix B and in the library.
...
Code Block | ||||
---|---|---|---|---|
| ||||
public class VideoPlayer extends SpringStreamsActivity { VideoView videoView; /** * */ public VideoPlayer() { super("test", "Streaming Test App"); } public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); videoView = ...; } @Override protected void onStart() { Map<String, Object> atts = new HashMap<String, Object>(); atts.put("stream", "android/teststream"); super.track(new VideoViewAdapter(this.videoView), atts); super.onStart(); } } |
Appendix A
Anchor | ||||
---|---|---|---|---|
|
In the following example, the adapter has been implemented for the VideoView
from the standard API.
Code Block | ||
---|---|---|
| ||
/** * Implementation of an adapter for the {@link VideoView} in standard * android api. * * @author <a href="mailto:support@spring.de">spring GmbH & Co.KG</a> */ public class VideoViewAdapter implements StreamAdapter { private VideoView videoView; public VideoViewAdapter(VideoView videoView) { if(videoView == null) throw new NullPointerException("videoView may not be null"); this.videoView = videoView; } @Override public Meta getMeta() { return new Meta() { public String getPlayerName() { return "android.widget.VideoView"; } public String getPlayerVersion() { return Build.VERSION.RELEASE; } public int getScreenHeight() { return (((WindowManager)videoView.getContext().getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay()).getHeight(); } public int getScreenWidth() { return (((WindowManager)videoView.getContext().getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay()).getWidth(); } }; } @Override public int getPosition() { return (int)Math.round(videoView.getCurrentPosition()/1000.0); } @Override public int getDuration() { return (int)Math.round(videoView.getDuration()/1000.0); } @Override public int getWidth() { return videoView.getWidth(); } @Override public int getHeight() { return videoView.getHeight(); } } |
Appendix B
Anchor | ||||
---|---|---|---|---|
|
The source code of class SpringStreamsActivity
...