Magento2 Media path in .phtml file

Mit*_*tul 4 php magento2 magento-2.0

I have tried lots of option in magento2 to find the media path URL

How can i find the media path URL in template.

I have try

$object_manager = Magento\Core\Model\ObjectManager::getInstance();
$dir = $object_manager->get('Magento\App\Dir');
$mediaUrl = $dir->getDir(\Magento\App\Dir::MEDIA);
Run Code Online (Sandbox Code Playgroud)

But it give me error class not found. I have search and found the one solution to create function in block file but there are so many places i want to use the media path in my design

Thanks in advance.

198*_*984 5

这是从块或模板内部获取媒体路径的方式。

$this->getUrl('pub/media')
Run Code Online (Sandbox Code Playgroud)