How to play YouTube videos in background in android?

It is possible to play the audio in the background. However , you are not allowed to do so.

This violation of the Youtube API is cause for immidiate removal from the play store.

Official answer:

During review, we found that your app violates the Prohibited Actions provision of the Content Policy.

We have determined that your app enables background playing of YouTube videos, which is a violation of the YouTube API Terms of Service: "Your API Client will not, and You will not encourage or create functionality for Your users or other third parties to: (8) separate, isolate, or modify the audio or video components of any YouTube audiovisual content made available through the YouTube API;"