Initial implementation of media integration

Not quite ready to merge, but good enough to experiment with.