Grabbing video/image from post without text

Sorry if i have posted this in the wrong area, im new here.

Im new to wordpress and have been trying to get to grips with how to call different elements in the loop. Im having troubble grabbling the first video/image in a post without grabbing the other content. Im only posting either a video or and image and some text but i want to pull the video/image seperatly in the loop.

to grabb images, open your functions.php and add this :


function catch_that_image() {
  global $post, $posts;
  $first_img = '';
  ob_start();
  ob_end_clean();
  $output = preg_match_all('/<img.+src=[\\'"]([^\\'"]+)[\\'"].*>/i', $post->post_content, $matches);
  $first_img = $matches [1] [0];

  if(empty($first_img)){ //Defines a default image
    $first_img = "/images/default.jpg";
  }
  return $first_img;
}

Once done, you can call the function within the loop to display the first image from the post:

<?php echo catch_that_image() ?>

Goodluck