         }
     }
     
+    func hkwDeviceStateUpdated(deviceid: Int64, withReason reason: Int) {
+        print("hkwDeviceStateUpdated")
+        
+        let deviceInfo = HKWControlHandler.sharedInstance().getDeviceInfoById(deviceid)
+        if !deviceInfo.active {
+            HKWControlHandler.sharedInstance().addDeviceToSession(deviceInfo.deviceId)
+        }
+    }
+    
+    func hkwErrorOccurred(errorCode: Int, withErrorMessage errorMesg: String!) {
+        print("Error occured: errorCode:\(errorCode), mesg:\(errorMesg)")
+        g_alert = UIAlertController(title: "Error", message: errorMesg, preferredStyle: .Alert)
+        g_alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
+        self.presentViewController(g_alert, animated: true, completion: nil)
+    }
+    
     func hkwPlayEnded() {
         HKWControlHandler.sharedInstance().stop()
+        self.playCurrentIndex()
     }
 }

                if self.g_alert != nil {
                    self.g_alert.dismissViewControllerAnimated(true, completion: nil)
                }
            })
        }
    }
    
    func loadAssets() {

    }
}

class GameViewController:UIViewController, MTKViewDelegate, HKWPlayerEventHandlerDelegate, HKWDeviceEventHandlerDelegate {
    let device: MTLDevice = MTLCreateSystemDefaultDevice()!
    
    let g_licenseKey = "2FA8-2FD6-C27D-47E8-A256-D011-3751-2BD6"
