I am using OnePlus Two and I want to play the offline videos from YouTube in the locked screen.
The solution mentioned in the below link does not work: Lock screen while playing YouTube video
Is there any way that it can be done?
You can try using SnapTube. It let's you download videos (or just the audio) from a number of sources, including Youtube. If you download only the audio, you can just use any standard audio player (or the built-in one) to listen to it with the screen off.
Disclaimer: not sure how this fits with Youtube terms of service, you may want to investigate that before using it on Youtube.