I'm new to Flash Access and trying to setup a basic player with OSMF (1.5). I read "Understanding the protected content workflow" and find it is for flv & flv.metadata. From that document, I can only send authenticate token after the DRMContentData is created. So this is the recommend workflow:

Load .metadata file

new DRMContentData with the loaded data

set authenticate token by drmManager.setAuthenticationToken

load voucher

But when I try F4M file with OSMF player, things are changed. After the .f4m file is loaded by mediaFactory.createMediaElement(new URLResource(URL)), OSMF starts to do the authenticate by itself without give me a chance to set my token. The first event from DRMEvent.DRM_STATE_CHANGE I received is DRMState.AUTHENTICATION_ERROR, and there is no DRMContentData anywhere I can use to send my token.

I can see one request has been sent out to license server from Fiddler but the return value has limited readle words, some of them are:

Are you attempting to set a custom authentication token? "drmManager.setAuthenticationToken()" is only used if you want to manually set your own custom token, or if you want to change the authentication token that is issued to a client.

Normally, here is the workflow:

1. Create DRMContentData from metadata

2. Set your user credentials with drmManager.authenticate()

3. Flash Access will talk to the server, and then retrieve an authentication token.

4. Now, every time the client talks to the server (like during drmManager.loadVoucher()), the authentication token from step #4 will automatically be attached to the license request. You do not have to ever call .setAuthenticationToken() unless you want to override this token.

Thanks for the reply. The workflow you mentioned is documented in the link I provided and I read it before. The issue I have now is I'm now trying to load a .f4m file (generated by f4mpackage to support http dynamic streaming), I don't have a .metadata file so I can't greate the DRMContentData for doing the authenticate. With OSMF, I pass the url of .f4m file to MediaElement and it handles all the rest.

Do you mean even we package a f4m file, we can generate the .metadata file at the same time?

The .f4m file is actually a manifest file. Within that file (if you open it in a web browser), you'll see that it actually references a DRM Metadata. OSMF automatically parses this manifest and extracts the metadata present in the <drmAdditionalHeader> tag. If you need access to that metadata, it is available via:

resource.drmContentData (for single bitrate scenarios)

In the resource DRM metadata namespace (for multi-bitrate scenarios)

Here is a helper function that'll return the extracted content metadata for a specified resource. When the media element is ready, you have access to the drmContentData and can start any custom authorization/authentication workflow. Otherwise once the playback has been started, OSMF will follow the default workflow.

/**
* @private
*
* Checks for DMR metadata both in SBR and MBR cases. In SBR case, the DRM metadata is
* saved in drmContentData property. In MBR case, the DRM metadata can
* also be present as stream-based metadata in DRM namespace. In this case, we will
* return the medatata for the specified stream.
*/
private function getDRMContentData(resource:MediaResourceBase, streamName:String):ByteArray
{
if (streamName == null)
{
return null;
}
var streamingResource:StreamingURLResource = resource as StreamingURLResource;
if (streamingResource != null)
{
// [CASE 1] We are in SBR or MBR case where the DRM metadata is
// present in drmContentData property so we just return it.
if (streamingResource.drmContentData != null)
{
return streamingResource.drmContentData;
}
// [CASE 2] We have a DRM namespace associated with this resource
// which may contain the actual drmData.
var drmMetadata:Metadata = resource.getMetadataValue(MetadataNamespaces.DRM_METADATA) as Metadata;
if (drmMetadata != null && drmMetadata.keys.length > 0)
{
return drmMetadata.getValue(streamName) as ByteArray;
}
}
return null;
}

But, if you would like access to the DRM metadata before starting playback, below is sample code which will wait for the READY state in the player before trying to get the metadata.

Thanks for the demo code. I think you showed me the workflow I want. But there is one problem with the code. The package "org.osmf.metadata.MetadataNamespaces" can not be found neither in OSMF 1.5 nor 1.6. So I can not use "MetadataNamespaces.DRM_METADATA". And searching on Adobe doesn't return me useful results. Is there anything I can do with this?

Usually this kind of error indicates that the player is linking with the wrong version of the OSMF.swc ( probably version 1.0 which is delivered with the Flex SDK). The recommended way is to update the project setting to link with a specific version of OSMF.swc and not with version 1.0

If you are using Flash Builder then:

1. go to project properties page of the player

2. go to "ActionScript Build Path" section

3. make sure that "Library path" tab is selected

4. in the "Build path libraries" tree expand "Flex SDK" node

5. it should list a bunch of swc which will be linked with your project

6. select the osmf.swc and click "Remove"

7a. if you want to use the compile SWC, then press "Add SWC..." and select the OSMF.swc version 1.5 or version 1.6 downloaded on your system

7b. if you want to use the project, the press "Add Project..." and select the OSMF project imported from the sources in your workspace.

8. press "OK" to save the changes

Clean and compile. It should work.

You may also copy the osmf.swc vversion 1.5 or 1.6 over the osmf.swc in the Flex SDK directory.

I removed the osmf.swc inside the sdk and link to a new 1.5 version. I checked the source code and found the org.osmf.metadata.MetadataNamespaces is marked [Internal] so no ourside link is allowed. But since I can access the source, I know the string value and I can use it directly.

The MetadataNamespaces class is only excluded from ASDoc generation process through [ExcludeClass] metadata ( kind of ironic i know ) but it should be available for using if imported directly. The code provided above should compile without warning or errors related to MetadataNamespaces class.

I find the getDRMContentData doesn't work for my test content (the url I sent you by private email). It's a MBR content so it goes to case 2. But drmMetadata returns null after run the code and so the getDRMContentData returns null. I call this right after the DRMTrait is loaded. My purpose is to send custom data to server by using setAuthenticationToken which requires a drmContentData.