ASCIInema Player integration nc16

#1

Hi, i am starting a project for an app that is based on the pdf viewer.
the project should allow native support for “.cast” files to be viewed in nextcloud like opening pds currently. ( looks like this: https://asciinema.org/a/14?t=25&speed=2&theme=solarized-dark)

the javascript library i want to use is https://github.com/asciinema/asciinema-player

it should trigger whenever you want to open a cast file via webapp or mobile app.

the usage of the player is fairly simple and looks something like this:

<html>
<head>
  ...
  <link rel="stylesheet" type="text/css" href="/asciinema-player.css" />
  ...
</head>
<body>
  ...
  <asciinema-player src="/demo.cast"></asciinema-player>
  ...
  <script src="/asciinema-player.js"></script>
</body>
</html>

i was able to generate a git repository for the project: https://github.com/jrsmile/files_castviewer
it is forked from the nextcloud/files_pdfviewer.

it just started but if somebody wants to join the team feel free to contribute.

2 Likes
#2

what i found so far is that i have to register a mime type for .cast files like:
<?php

namespace OCA\CastViewer\Migration;

use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use OCP\ILogger;

class RegisterMimeType implements IRepairStep {
    protected $logger;
    private $customMimetypeMapping;

public function __construct(ILogger $logger) {
    $this->logger = $logger;

    // Define the custom mimetype mapping
    $this->customMimetypeMapping = array(
        "cast" => array("application/cast")
    );
}

public function getName() {
    return 'Register MIME type for "application/cast"';
}

private function registerForExistingFiles() {
    $mimetypeMapping = $this->customMimetypeMapping;
    $mimeTypeLoader = \OC::$server->getMimeTypeLoader();

    foreach($mimetypeMapping as $mimetypeKey => $mimetypeValues) {
        foreach($mimetypeValues as $mimetypeValue) {
            $mimeId = $mimeTypeLoader->getId($mimetypeValue);
            $mimeTypeLoader->updateFilecache($mimetypeKey, $mimeId);
        }
    }
}

private function registerForNewFiles() {
    $mimetypeMapping = $this->customMimetypeMapping;
    $mimetypeMappingFile = \OC::$configDir . 'mimetypemapping.json';

    if (file_exists($mimetypeMappingFile)) {
        $existingMimetypeMapping = json_decode(file_get_contents($mimetypeMappingFile), true);
        $mimetypeMapping = array_merge($existingMimetypeMapping, $mimetypeMapping);
    }

    file_put_contents($mimetypeMappingFile, json_encode($mimetypeMapping, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
}

public function run(IOutput $output) {
    $this->logger->info('Registering the mimetype...');

    // Register the mime type for existing files
    $this->registerForExistingFiles();

    // Register the mime type for new files
    $this->registerForNewFiles();

    $this->logger->info('The mimetype was successfully registered.');
}
}
#3

and to register a default action like:

OCA.Files.fileActions.registerAction({
name: ‘audio’,
displayName: ‘audio’,
mime: mime,
permissions: OC.PERMISSION_READ,
icon: icon_url,
actionHandler: playFile
});
OCA.Files.fileActions.setDefault(mime, ‘audio’);

But how do i tell my template php which file to open?

#4

It’s definitely a good idea for an app!

It would be nice to have the player also for the public shares.

Thank you; I am looking forward to see it ready!