This project is read-only.

Getting Started: JavaScript

Setting up the Logging service and target

1. Add the Microsoft Player Framework Analytics Plugin to your project references.
AI_JS_References.png
2. Add a configuration file to your project to tell the Audience Insight logging target where to send the data. Here is a sample config file you can use to get started. Note: you'll need to modify the file to point to your live Audience Insight service endpoint.
3. At app launch, create an Audience Insight logging target responsible for sending your logs to an Audience Insight server.
// wire up a logging target that will batch and send all logs to an MS Audience Insight server
Microsoft.VideoAnalytics.BatchingConfigFactory.load(new Windows.Foundation.Uri("ms-appx:///AudienceInsightConfig.xml")).then(
    function (batchingConfig) {
        var audienceInsightTarget = new Microsoft.VideoAnalytics.BatchingLogAgent(batchingConfig);
        Microsoft.VideoAnalytics.LoggingService.current.loggingTargets.append(audienceInsightTarget);
(args.detail.arguments));
    }
);
Note: Be sure the path to your config xml file is correct
4. Optionally, generate a new log that indicates your application has started. Pass in any startup parameters used to launch your app.
app.onactivated = function (args) {
...
Microsoft.VideoAnalytics.LoggingService.current.log(new Microsoft.VideoAnalytics.AppStartLog(args.detail.arguments));
...
};
5. Optionally, setup the error logging service that can generate logs when unhandled exceptions occur.
errorLogger = new PlayerFramework.Analytics.ErrorLogger();
Note: errorLogger will continue to operate as long as it remains in scope. Always call errorLogger.dispose() when you are finished with it.

That's all! The analytics plugin will automatically load and wire up to the smooth streaming SDK (if present) to start generating logs when you play media in your app using the player framework.

Optional Configuration

If you want greater control over how the analytics plugin operates, you can supply a custom config file:
Microsoft.VideoAnalytics.AnalyticsConfig.load(new Windows.Foundation.Uri("ms-appx:///AnalyticsConfig.xml")).then(
    function (analyticsConfig) {
        mediaPlayer.analyticsPlugin.analyticsConfig = analyticsConfig;
    });

Getting Started: Xaml

Setting up the Logging service and target

1. Add the Microsoft Player Framework Analytics Plugin to your project references.
AI_Xaml_References.png
2. Add a configuration file to your project to tell the Audience Insight logging target where to send the data. Here is a sample config file you can use to get started. Note: you'll need to modify the file to point to your live Audience Insight service endpoint.
3. At app launch, create an Audience Insight logging target responsible for sending your logs to an Audience Insight server.
// wire up a logging target that will batch and send all logs to an MS Audience Insight server
var batchingConfig = await Microsoft.VideoAnalytics.BatchingConfigFactory.Load(new Uri("ms-appx:///AudienceInsightConfig.xml"));
var audienceInsightTarget = new Microsoft.VideoAnalytics.BatchingLogAgent(batchingConfig);
Microsoft.VideoAnalytics.LoggingService.Current.LoggingTargets.Add(audienceInsightTarget);
Note: Be sure the path to your config xml file is correct
4. Optionally, generate a new log that indicates your application has started. Pass in any startup parameters used to launch your app.
protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
...
Microsoft.VideoAnalytics.LoggingService.Current.Log(new Microsoft.VideoAnalytics.AppStartLog(args.Arguments));
...
}
5. Optionally, setup the error logging service that can generate logs when unhandled exceptions occur.
errorLogger = new Microsoft.PlayerFramework.Analytics.ErrorLogger();
Note: errorLogger will continue to operate as long as it remains in scope. Always call errorLogger.Dispose() when you are finished with it.

Initializing the MediaPlayer

1. Connect the AdaptivePlugin to a new AnalyticsPlugin.
// get the adaptive plugin
var adaptivePlugin = player.Plugins.OfType<AdaptivePlugin>().FirstOrDefault();
var analyticsPlugin = new AnalyticsPlugin(new AnalyticsConfig());
// init the analytics plugin with an object that can provide adaptive streaming info (optional)
var adaptiveMonitorFactory = new AdaptiveMonitorFactory(adaptivePlugin.Manager);
analyticsPlugin.AdaptiveMonitor = adaptiveMonitorFactory.AdaptiveMonitor;
// last, expose the analytics plugin to the player framework
player.Plugins.Add(analyticsPlugin);
2. Note: AdaptiveMonitorFactory needs to be disposed when you are done with the MediaPlayer.

That's all! The analytics plugin will automatically will start generating logs when you play media in your app using the player framework.

Optional Configuration

If you want greater control over how the analytics plugin operates, you can supply a custom config file. Due to the async nature of creating a config file, we recommend moving all plugin initialization code above to the deferrable MediaPlayer.Initializing event.
player.Initializing += player_Initializing;

async void player_Initializing(object sender, MediaPlayerDeferrableEventArgs e)
{
    var deferral = e.DeferrableOperation.GetDeferral();

    // get the adaptive plugin
    var adaptivePlugin = player.Plugins.OfType<AdaptivePlugin>().FirstOrDefault();
    var analyticsConfig = await AnalyticsConfig.Load(new Uri("ms-appx:///AnalyticsConfig.xml"));
    var analyticsPlugin = new AnalyticsPlugin(analyticsConfig);
    // init the analytics plugin with an object that can provide adaptive streaming info (optional)
    var adaptiveMonitorFactory = new AdaptiveMonitorFactory(adaptivePlugin.Manager);
    analyticsPlugin.AdaptiveMonitor = adaptiveMonitorFactory.AdaptiveMonitor;
    // last, expose the analytics plugin to the player framework
    player.Plugins.Add(analyticsPlugin);

    deferral.Complete();
}

Getting Started: WP8

Setting up the Logging service and target

1. Add the Microsoft Player Framework Analytics Plugin to your project references.
AI_WP8_References.png
2. Add a configuration file to your project to tell the Audience Insight logging target where to send the data. Here is a sample config file you can use to get started. Note: you'll need to modify the file to point to your live Audience Insight service endpoint.
3. At app launch, create an Audience Insight logging target responsible for sending your logs to an Audience Insight server.
// wire up a logging target that will batch and send all logs to an MS Audience Insight server
var batchingConfig = await Microsoft.VideoAnalytics.BatchingConfigFactory.Load(new Uri("ms-appx:///AudienceInsightConfig.xml"));
var audienceInsightTarget = new Microsoft.VideoAnalytics.BatchingLogAgent(batchingConfig);
Microsoft.VideoAnalytics.LoggingService.Current.LoggingTargets.Add(audienceInsightTarget);
Note: Be sure the path to your config xml file is correct
4. Optionally, generate a new log that indicates your application has started. Pass in any startup parameters used to launch your app.
private async void Application_Launching(object sender, LaunchingEventArgs e)
{
...
Microsoft.VideoAnalytics.LoggingService.Current.Log(new Microsoft.VideoAnalytics.AppStartLog(null));
...
}
5. Optionally, setup the error logging service that can generate logs when unhandled exceptions occur.
errorLogger = new Microsoft.PlayerFramework.Analytics.ErrorLogger();
Note: errorLogger will continue to operate as long as it remains in scope. Always call errorLogger.Dispose() when you are finished with it.

Initializing the MediaPlayer

1. Connect the AdaptivePlugin to a new AnalyticsPlugin.
var analyticsPlugin = new AnalyticsPlugin(new AnalyticsConfig());
analyticsPlugin.Dispatcher = System.Windows.Deployment.Current.Dispatcher;
// init the analytics plugin with an object that can provide adaptive streaming info (optional)
analyticsPlugin.AdaptiveMonitor = new AdaptiveMonitor(adaptivePlugin.SSME);
// last, expose the analytics plugin to the player framework
player.Plugins.Add(analyticsPlugin);
2. Note: AdaptiveMonitorFactory needs to be disposed when you are done with the MediaPlayer.

That's all! The analytics plugin will automatically will start generating logs when you play media in your app using the player framework.

Optional Configuration

If you want greater control over how the analytics plugin operates, you can supply a custom config file. Due to the async nature of creating a config file, we recommend moving all plugin initialization code above to the deferrable MediaPlayer.Initializing event.
player.Initializing += player_Initializing;

async void player_Initializing(object sender, MediaPlayerDeferrableEventArgs e)
{
    var deferral = e.DeferrableOperation.GetDeferral();

    var analyticsConfig = await AnalyticsConfig.Load(new Uri("ms-appx:///AnalyticsConfig.xml"));
    var analyticsPlugin = new AnalyticsPlugin(analyticsConfig);
    analyticsPlugin.Dispatcher = System.Windows.Deployment.Current.Dispatcher;
    // init the analytics plugin with an object that can provide adaptive streaming info (optional)
    analyticsPlugin.AdaptiveMonitor = new AdaptiveMonitor(adaptivePlugin.SSME);
    // last, expose the analytics plugin to the player framework
    player.Plugins.Add(analyticsPlugin);

    deferral.Complete();
}

Last edited Apr 12, 2013 at 11:06 PM by timgreenfield, version 24