Tips for using Widevine iOS SDK

Get license for a local file:

  • If the file has not been registered before, call WV_Register() to register the file to WV local DB.
  • Re-register a pre-registered file returns 4100 from WV_Register().
  • After register success, call WV_NowOnline() to get license from lic server.
  • You need to make sure WV_Register() returns success before call WV_NowOnline. With 4100 returned from WV_Register(), WV_NowOnline() does nothing for you (it won’t go online and acquire the license). If 4100 returned but you don’t have valid license now, UnRegister this file and ReRegister it again followed a WV_NowOnline call.
  • If WV_NowOnline is called without network connection, it doesn’t return anything. So make sure you check the network connection before call this API.
  • If license acquisition fails, WViOsApiEvent_EMMFailed will be dispatched. Check “WVStatusKey” in its attribute and the value should be 6 which means “No license”.
  • If license acquisition success, you might receive WViOsApiEvent_EMMFailed first with WVStatusKey set to 6, and you will receive WViOsApiEvent_QueryStatus some time after that with WVStatusKey set to 0 which means OK (license is ready).

So this is what you need to do for acquiring the license:

  1. Get the local file ready.
  2. Call WV_Register() to register the file.
  3. Check the return value:
    1. If its OK (0), call WV_QueryAssetStatus and check the WVStatusKey.
      1. 0: License is ready. You can go and play the title.
      2. 6 (and other): No license, pls go and do next steps.
    2. If it fails with 4100, call WV_UnregisterAsset first and WV_RegisterAsset again.
  4. Check if it’s online now, only call WV_NowOnline when the network connection is live.
  5. Call WV_NowOnline()
    1. Wait for status callback event
      1. If WViOsApiEvent_EMMReceived, we are done.
      2. If WViOsApiEvent_EMMFailed, wait a second (maybe two) to see if you can receive the WViOsApiEvent_QueryStatus event. If you cannot, keep calling WV_QueryAssetStatus() after that for about 10 times (1 per second)
    2. Check the WVStatusKey in WViOsApiEvent_QueryStatus
      1. 0: License is ready. You can go and play the title.
      2. 6 (and other): No license.
  6. Done.

Now you can call WV_Play() to play the video.

How to check if you have a license for a video:

  • Call WV_QueryAssetStatus(filePath)
  • In the WViOsApiEvent_QueryStatus event, check WVStatusKey
    • 0: License is ready. You can go and play the title.
    • 6 (and other): No license.
Advertisements

悬浮在空中的小球

今天在网上看到一个MIT实验室正在做的项目,一个由磁力控制的,能悬浮在空中的小金属球。单单从原理上讲貌似也不难理解,但最终的效果却让人感觉不可思议。有点像科幻电影。试想这个技术以后如果能够推广到其他的物体以及环境,该有多酷啊。废话不多,看视频吧。

How-to: Detect iOS device type

Although Apple doesn’t want you to design your app for a special device in its device list, there always will be sometime you need to know if the device user is using is the one you want to enable/disable some features in your app. iOS SDK provide a UIDevice class for some basic system information like OS version and device type. But if you want to know if it is an iPhone 3GS or iPad 1, you might need some help.

I recently need the kind of information in one of my project. We’d like to provide videos in different quality for different devices. Though the app the same one, the asset will be different for different devices. In order to get the detail device information, I use an extension of UIDevice from GitHub. There is not need to import the entire extension to your project, only the UIDevice-Hardware would be enough.

The extension provides convenient method to get device/platform name. By calling the following API, you will be served with what your want.

[[UIDevice currentDevice] platformString]

Please note that this extension has been updated for at least 6 months, it stil uses iPad3 and iPhone5. You need to update those strings by yourselves.