Skip to content

media

PlayerError dataclass

Corresponds to kMediaError

Source code in zendriver/cdp/media.py
@dataclass
class PlayerError:
    """
    Corresponds to kMediaError
    """

    error_type: str

    #: Code is the numeric enum entry for a specific set of error codes, such
    #: as PipelineStatusCodes in media/base/pipeline_status.h
    code: int

    #: A trace of where this error was caused / where it passed through.
    stack: typing.List[PlayerErrorSourceLocation]

    #: Errors potentially have a root cause error, ie, a DecoderError might be
    #: caused by an WindowsError
    cause: typing.List[PlayerError]

    #: Extra data attached to an error, such as an HRESULT, Video Codec, etc.
    data: dict

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["errorType"] = self.error_type
        json["code"] = self.code
        json["stack"] = [i.to_json() for i in self.stack]
        json["cause"] = [i.to_json() for i in self.cause]
        json["data"] = self.data
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> PlayerError:
        return cls(
            error_type=str(json["errorType"]),
            code=int(json["code"]),
            stack=[PlayerErrorSourceLocation.from_json(i) for i in json["stack"]],
            cause=[PlayerError.from_json(i) for i in json["cause"]],
            data=dict(json["data"]),
        )

cause: typing.List[PlayerError] instance-attribute

code: int instance-attribute

data: dict instance-attribute

error_type: str instance-attribute

stack: typing.List[PlayerErrorSourceLocation] instance-attribute

__init__(error_type, code, stack, cause, data)

from_json(json) classmethod

Source code in zendriver/cdp/media.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> PlayerError:
    return cls(
        error_type=str(json["errorType"]),
        code=int(json["code"]),
        stack=[PlayerErrorSourceLocation.from_json(i) for i in json["stack"]],
        cause=[PlayerError.from_json(i) for i in json["cause"]],
        data=dict(json["data"]),
    )

to_json()

Source code in zendriver/cdp/media.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["errorType"] = self.error_type
    json["code"] = self.code
    json["stack"] = [i.to_json() for i in self.stack]
    json["cause"] = [i.to_json() for i in self.cause]
    json["data"] = self.data
    return json

PlayerErrorSourceLocation dataclass

Represents logged source line numbers reported in an error. NOTE: file and line are from chromium c++ implementation code, not js.

Source code in zendriver/cdp/media.py
@dataclass
class PlayerErrorSourceLocation:
    """
    Represents logged source line numbers reported in an error.
    NOTE: file and line are from chromium c++ implementation code, not js.
    """

    file: str

    line: int

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["file"] = self.file
        json["line"] = self.line
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> PlayerErrorSourceLocation:
        return cls(
            file=str(json["file"]),
            line=int(json["line"]),
        )

file: str instance-attribute

line: int instance-attribute

__init__(file, line)

from_json(json) classmethod

Source code in zendriver/cdp/media.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> PlayerErrorSourceLocation:
    return cls(
        file=str(json["file"]),
        line=int(json["line"]),
    )

to_json()

Source code in zendriver/cdp/media.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["file"] = self.file
    json["line"] = self.line
    return json

PlayerErrorsRaised dataclass

Send a list of any errors that need to be delivered.

Source code in zendriver/cdp/media.py
@event_class("Media.playerErrorsRaised")
@dataclass
class PlayerErrorsRaised:
    """
    Send a list of any errors that need to be delivered.
    """

    player_id: PlayerId
    errors: typing.List[PlayerError]

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> PlayerErrorsRaised:
        return cls(
            player_id=PlayerId.from_json(json["playerId"]),
            errors=[PlayerError.from_json(i) for i in json["errors"]],
        )

errors: typing.List[PlayerError] instance-attribute

player_id: PlayerId instance-attribute

__init__(player_id, errors)

from_json(json) classmethod

Source code in zendriver/cdp/media.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> PlayerErrorsRaised:
    return cls(
        player_id=PlayerId.from_json(json["playerId"]),
        errors=[PlayerError.from_json(i) for i in json["errors"]],
    )

PlayerEvent dataclass

Corresponds to kMediaEventTriggered

Source code in zendriver/cdp/media.py
@dataclass
class PlayerEvent:
    """
    Corresponds to kMediaEventTriggered
    """

    timestamp: Timestamp

    value: str

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["timestamp"] = self.timestamp.to_json()
        json["value"] = self.value
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> PlayerEvent:
        return cls(
            timestamp=Timestamp.from_json(json["timestamp"]),
            value=str(json["value"]),
        )

timestamp: Timestamp instance-attribute

value: str instance-attribute

__init__(timestamp, value)

from_json(json) classmethod

Source code in zendriver/cdp/media.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> PlayerEvent:
    return cls(
        timestamp=Timestamp.from_json(json["timestamp"]),
        value=str(json["value"]),
    )

to_json()

Source code in zendriver/cdp/media.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["timestamp"] = self.timestamp.to_json()
    json["value"] = self.value
    return json

PlayerEventsAdded dataclass

Send events as a list, allowing them to be batched on the browser for less congestion. If batched, events must ALWAYS be in chronological order.

Source code in zendriver/cdp/media.py
@event_class("Media.playerEventsAdded")
@dataclass
class PlayerEventsAdded:
    """
    Send events as a list, allowing them to be batched on the browser for less
    congestion. If batched, events must ALWAYS be in chronological order.
    """

    player_id: PlayerId
    events: typing.List[PlayerEvent]

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> PlayerEventsAdded:
        return cls(
            player_id=PlayerId.from_json(json["playerId"]),
            events=[PlayerEvent.from_json(i) for i in json["events"]],
        )

events: typing.List[PlayerEvent] instance-attribute

player_id: PlayerId instance-attribute

__init__(player_id, events)

from_json(json) classmethod

Source code in zendriver/cdp/media.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> PlayerEventsAdded:
    return cls(
        player_id=PlayerId.from_json(json["playerId"]),
        events=[PlayerEvent.from_json(i) for i in json["events"]],
    )

PlayerId

Bases: str

Players will get an ID that is unique within the agent context.

Source code in zendriver/cdp/media.py
class PlayerId(str):
    """
    Players will get an ID that is unique within the agent context.
    """

    def to_json(self) -> str:
        return self

    @classmethod
    def from_json(cls, json: str) -> PlayerId:
        return cls(json)

    def __repr__(self):
        return "PlayerId({})".format(super().__repr__())

__repr__()

Source code in zendriver/cdp/media.py
def __repr__(self):
    return "PlayerId({})".format(super().__repr__())

from_json(json) classmethod

Source code in zendriver/cdp/media.py
@classmethod
def from_json(cls, json: str) -> PlayerId:
    return cls(json)

to_json()

Source code in zendriver/cdp/media.py
def to_json(self) -> str:
    return self

PlayerMessage dataclass

Have one type per entry in MediaLogRecord::Type Corresponds to kMessage

Source code in zendriver/cdp/media.py
@dataclass
class PlayerMessage:
    """
    Have one type per entry in MediaLogRecord::Type
    Corresponds to kMessage
    """

    #: Keep in sync with MediaLogMessageLevel
    #: We are currently keeping the message level 'error' separate from the
    #: PlayerError type because right now they represent different things,
    #: this one being a DVLOG(ERROR) style log message that gets printed
    #: based on what log level is selected in the UI, and the other is a
    #: representation of a media::PipelineStatus object. Soon however we're
    #: going to be moving away from using PipelineStatus for errors and
    #: introducing a new error type which should hopefully let us integrate
    #: the error log level into the PlayerError type.
    level: str

    message: str

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["level"] = self.level
        json["message"] = self.message
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> PlayerMessage:
        return cls(
            level=str(json["level"]),
            message=str(json["message"]),
        )

level: str instance-attribute

message: str instance-attribute

__init__(level, message)

from_json(json) classmethod

Source code in zendriver/cdp/media.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> PlayerMessage:
    return cls(
        level=str(json["level"]),
        message=str(json["message"]),
    )

to_json()

Source code in zendriver/cdp/media.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["level"] = self.level
    json["message"] = self.message
    return json

PlayerMessagesLogged dataclass

Send a list of any messages that need to be delivered.

Source code in zendriver/cdp/media.py
@event_class("Media.playerMessagesLogged")
@dataclass
class PlayerMessagesLogged:
    """
    Send a list of any messages that need to be delivered.
    """

    player_id: PlayerId
    messages: typing.List[PlayerMessage]

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> PlayerMessagesLogged:
        return cls(
            player_id=PlayerId.from_json(json["playerId"]),
            messages=[PlayerMessage.from_json(i) for i in json["messages"]],
        )

messages: typing.List[PlayerMessage] instance-attribute

player_id: PlayerId instance-attribute

__init__(player_id, messages)

from_json(json) classmethod

Source code in zendriver/cdp/media.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> PlayerMessagesLogged:
    return cls(
        player_id=PlayerId.from_json(json["playerId"]),
        messages=[PlayerMessage.from_json(i) for i in json["messages"]],
    )

PlayerPropertiesChanged dataclass

This can be called multiple times, and can be used to set / override / remove player properties. A null propValue indicates removal.

Source code in zendriver/cdp/media.py
@event_class("Media.playerPropertiesChanged")
@dataclass
class PlayerPropertiesChanged:
    """
    This can be called multiple times, and can be used to set / override /
    remove player properties. A null propValue indicates removal.
    """

    player_id: PlayerId
    properties: typing.List[PlayerProperty]

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> PlayerPropertiesChanged:
        return cls(
            player_id=PlayerId.from_json(json["playerId"]),
            properties=[PlayerProperty.from_json(i) for i in json["properties"]],
        )

player_id: PlayerId instance-attribute

properties: typing.List[PlayerProperty] instance-attribute

__init__(player_id, properties)

from_json(json) classmethod

Source code in zendriver/cdp/media.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> PlayerPropertiesChanged:
    return cls(
        player_id=PlayerId.from_json(json["playerId"]),
        properties=[PlayerProperty.from_json(i) for i in json["properties"]],
    )

PlayerProperty dataclass

Corresponds to kMediaPropertyChange

Source code in zendriver/cdp/media.py
@dataclass
class PlayerProperty:
    """
    Corresponds to kMediaPropertyChange
    """

    name: str

    value: str

    def to_json(self) -> T_JSON_DICT:
        json: T_JSON_DICT = dict()
        json["name"] = self.name
        json["value"] = self.value
        return json

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> PlayerProperty:
        return cls(
            name=str(json["name"]),
            value=str(json["value"]),
        )

name: str instance-attribute

value: str instance-attribute

__init__(name, value)

from_json(json) classmethod

Source code in zendriver/cdp/media.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> PlayerProperty:
    return cls(
        name=str(json["name"]),
        value=str(json["value"]),
    )

to_json()

Source code in zendriver/cdp/media.py
def to_json(self) -> T_JSON_DICT:
    json: T_JSON_DICT = dict()
    json["name"] = self.name
    json["value"] = self.value
    return json

PlayersCreated dataclass

Called whenever a player is created, or when a new agent joins and receives a list of active players. If an agent is restored, it will receive the full list of player ids and all events again.

Source code in zendriver/cdp/media.py
@event_class("Media.playersCreated")
@dataclass
class PlayersCreated:
    """
    Called whenever a player is created, or when a new agent joins and receives
    a list of active players. If an agent is restored, it will receive the full
    list of player ids and all events again.
    """

    players: typing.List[PlayerId]

    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> PlayersCreated:
        return cls(players=[PlayerId.from_json(i) for i in json["players"]])

players: typing.List[PlayerId] instance-attribute

__init__(players)

from_json(json) classmethod

Source code in zendriver/cdp/media.py
@classmethod
def from_json(cls, json: T_JSON_DICT) -> PlayersCreated:
    return cls(players=[PlayerId.from_json(i) for i in json["players"]])

Timestamp

Bases: float

Source code in zendriver/cdp/media.py
class Timestamp(float):
    def to_json(self) -> float:
        return self

    @classmethod
    def from_json(cls, json: float) -> Timestamp:
        return cls(json)

    def __repr__(self):
        return "Timestamp({})".format(super().__repr__())

__repr__()

Source code in zendriver/cdp/media.py
def __repr__(self):
    return "Timestamp({})".format(super().__repr__())

from_json(json) classmethod

Source code in zendriver/cdp/media.py
@classmethod
def from_json(cls, json: float) -> Timestamp:
    return cls(json)

to_json()

Source code in zendriver/cdp/media.py
def to_json(self) -> float:
    return self

disable()

Disables the Media domain.

Source code in zendriver/cdp/media.py
def disable() -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Disables the Media domain.
    """
    cmd_dict: T_JSON_DICT = {
        "method": "Media.disable",
    }
    json = yield cmd_dict

enable()

Enables the Media domain

Source code in zendriver/cdp/media.py
def enable() -> typing.Generator[T_JSON_DICT, T_JSON_DICT, None]:
    """
    Enables the Media domain
    """
    cmd_dict: T_JSON_DICT = {
        "method": "Media.enable",
    }
    json = yield cmd_dict