How does a computer play a video while doing something else?
This is implemented using several different techniques.  Within the application (for example, the web browser), the program can execute different threads of execution.  One thread can perform the video streaming/playback, while a different thread can handle the user typing into the comment field.

These threads, along with many other threads and processes, are in turn scheduled by the operating system (even if you only have the web browser open, the operating system has many background tasks running, such as the windowing manager, the print spooler, the USB device manager, etc).  It is the job of the OS scheduler to determine which thread can actively run, on which processor core, and for how long.  In a typical system, a thread can run for up to some threshold value, suppose 100 milliseconds, before the scheduler allows another task to run.

This task switching is fundamental to all modern operating systems (Windows, Linux, UNIX, etc), and is usually a significant portion of an undergraduate operating systems course.