After few days straggling, I decide to change a direction and resolve the problem.
- change CNAME back to mydomain.com on DNS server.
- In Azure CDN profile, add a new custom domain cdn.mydomain.com and enable https
- install a WordPress plugin to update all my media files urls from www.mydomain.com/mediafiles to cdn.mydomain.com/mediafiles
now my users could visit www without any issue and all my images and videos are displayed correctly.