Ejemplo n.º 1
0
        /// <summary>
        /// Gets the number of tracks.
        /// </summary>
        /// <returns>The number of tracks.</returns>
        /// <remarks>
        /// The <see cref="Player"/> that owns this instance must be in the <see cref="PlayerState.Ready"/>,
        /// <see cref="PlayerState.Playing"/>, or <see cref="PlayerState.Paused"/> state.
        /// </remarks>
        /// <exception cref="ObjectDisposedException">The <see cref="Player"/> that this instance belongs to has been disposed of.</exception>
        /// <exception cref="InvalidOperationException">The <see cref="Player"/> that this instance belongs to is not in the valid state.</exception>
        /// <since_tizen> 3 </since_tizen>
        public int GetCount()
        {
            _owner.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);

            NativePlayer.GetTrackCount(_owner.Handle, _streamType, out var count).
            ThrowIfFailed(_owner, "Failed to get count of the track");

            Log.Info(PlayerLog.Tag, "get count : " + count);

            return(count);
        }
Ejemplo n.º 2
0
        private string GetCodecInfo(bool audioInfo)
        {
            Player.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);

            IntPtr audioPtr = IntPtr.Zero;
            IntPtr videoPtr = IntPtr.Zero;

            try
            {
                NativePlayer.GetCodecInfo(Player.Handle, out audioPtr, out videoPtr).
                ThrowIfFailed("Failed to get codec info");

                if (audioInfo)
                {
                    Log.Debug(PlayerLog.Tag, "it is audio case");
                    return(Marshal.PtrToStringAnsi(audioPtr));
                }
                else
                {
                    Log.Debug(PlayerLog.Tag, "it is video case");
                    return(Marshal.PtrToStringAnsi(videoPtr));
                }
            }
            finally
            {
                LibcSupport.Free(audioPtr);
                LibcSupport.Free(videoPtr);
            }
        }
Ejemplo n.º 3
0
        private Size GetVideoSize()
        {
            Player.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);

            NativePlayer.GetVideoSize(Player.Handle, out var width, out var height).
            ThrowIfFailed(Player, "Failed to get the video size");

            return(new Size(width, height));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the properties of the video.
        /// </summary>
        /// <returns>A <see cref="VideoStreamProperties"/> that contains the video stream information.</returns>
        /// <remarks>
        /// The <see cref="Multimedia.Player"/> that owns this instance must be in the <see cref="PlayerState.Ready"/>,
        /// <see cref="PlayerState.Playing"/>, or <see cref="PlayerState.Paused"/> state.
        /// </remarks>
        /// <exception cref="ObjectDisposedException">
        /// The <see cref="Multimedia.Player"/> that this instance belongs to has been disposed of.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// The <see cref="Multimedia.Player"/> that this instance belongs to is not in the valid state.
        /// </exception>
        /// <since_tizen> 3 </since_tizen>
        public VideoStreamProperties GetVideoProperties()
        {
            Player.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);

            NativePlayer.GetVideoStreamInfo(Player.Handle, out var fps, out var bitRate).
            ThrowIfFailed(Player, "Failed to get the video stream info");

            return(new VideoStreamProperties(fps, bitRate, GetVideoSize()));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the properties of the audio.
        /// </summary>
        /// <returns>A <see cref="AudioStreamProperties"/> that contains the audio stream information.</returns>
        /// <remarks>
        /// The <see cref="Multimedia.Player"/> that owns this instance must be in the <see cref="PlayerState.Ready"/>,
        /// <see cref="PlayerState.Playing"/>, or <see cref="PlayerState.Paused"/> state.
        /// </remarks>
        /// <exception cref="ObjectDisposedException">
        /// The <see cref="Multimedia.Player"/> that this instance belongs to has been disposed of.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// The <see cref="Multimedia.Player"/> that this instance belongs to is not in the valid state.
        /// </exception>
        /// <since_tizen> 3 </since_tizen>
        public AudioStreamProperties GetAudioProperties()
        {
            Player.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);

            NativePlayer.GetAudioStreamInfo(Player.Handle, out var sampleRate,
                                            out var channels, out var bitRate).
            ThrowIfFailed(Player, "Failed to get audio stream info");

            return(new AudioStreamProperties(sampleRate, channels, bitRate));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the duration.
        /// </summary>
        /// <returns>The duration of the stream.</returns>
        /// <remarks>
        /// The <see cref="Multimedia.Player"/> that owns this instance must be in the <see cref="PlayerState.Ready"/>,
        /// <see cref="PlayerState.Playing"/>, or <see cref="PlayerState.Paused"/> state.
        /// </remarks>
        /// <exception cref="ObjectDisposedException">
        /// The <see cref="Multimedia.Player"/> that this instance belongs to has been disposed of.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// The <see cref="Multimedia.Player"/> that this instance belongs to is not in the valid state.
        /// </exception>
        /// <since_tizen> 3 </since_tizen>
        public int GetDuration()
        {
            Player.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);

            NativePlayer.GetDuration(Player.Handle, out var duration).
            ThrowIfFailed(Player, "Failed to get the duration");

            Log.Info(PlayerLog.Tag, "get duration : " + duration);
            return(duration);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the duration in nanoseconds.
        /// </summary>
        /// <returns>The duration of the stream.</returns>
        /// <remarks>
        /// The <see cref="Multimedia.Player"/> that owns this instance must be in the <see cref="PlayerState.Ready"/>,
        /// <see cref="PlayerState.Playing"/>, or <see cref="PlayerState.Paused"/> state.
        /// </remarks>
        /// <exception cref="ObjectDisposedException">
        /// The <see cref="Multimedia.Player"/> that this instance belongs to has been disposed of.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// The <see cref="Multimedia.Player"/> that this instance belongs to is not in the valid state.
        /// </exception>
        /// <seealso cref="GetDuration"/>
        /// <since_tizen> 5 </since_tizen>
        public long GetDurationNanoseconds()
        {
            Player.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);

            NativePlayer.GetDurationNanoseconds(Player.Handle, out var duration).
            ThrowIfFailed(Player, "Failed to get the duration in nanoseconds");

            Log.Info(PlayerLog.Tag, "get duration(nsec) : " + duration);
            return(duration);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets information whether the current content of the player is spherical.
        /// </summary>
        /// <returns>True if the current content is spherical; otherwise false.</returns>
        /// <remarks>
        /// The <see cref="Player"/> that owns this instance must be in the <see cref="PlayerState.Ready"/>,
        /// <see cref="PlayerState.Playing"/>, or <see cref="PlayerState.Paused"/> state.
        /// </remarks>
        /// <feature>http://tizen.org/feature/opengles.version.2_0</feature>
        /// <feature>http://tizen.org/feature/multimedia.player.spherical_video</feature>
        /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
        /// <exception cref="ObjectDisposedException">The <see cref="Player"/> that this instance belongs to has been disposed of.</exception>
        /// <exception cref="InvalidOperationException">The <see cref="Player"/> that this instance belongs to is not in the valid state.</exception>
        /// <since_tizen> 5 </since_tizen>
        public bool IsSphericalContent()
        {
            ValidationUtil.ValidateFeatureSupported(PlayerFeatures.OpenGl);
            ValidationUtil.ValidateFeatureSupported(PlayerFeatures.SphericalVideo);

            Player.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);

            NativePlayer.IsSphericalContent(Player.Handle, out var value).
            ThrowIfFailed(Player, "Failed to get the spherical state of the content");

            return(value);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Pushes elementary stream to decode audio or video.
        /// </summary>
        /// <remarks>This source must be set as a source to a player and the player must be in the <see cref="PlayerState.Ready"/>,
        /// <see cref="PlayerState.Playing"/>, or <see cref="PlayerState.Paused"/> state.</remarks>
        /// <param name="packet">The <see cref="MediaPacket"/> to decode.</param>
        /// <exception cref="InvalidOperationException">
        ///     This source is not set as a source to a player.<br/>
        ///     -or-<br/>
        ///     The player is not in the valid state.
        /// </exception>
        /// <exception cref="ArgumentNullException"><paramref name="packet"/> is null.</exception>
        /// <exception cref="ObjectDisposedException"><paramref name="packet"/> has been disposed of.</exception>
        /// <exception cref="ArgumentException">
        ///     <paramref name="packet"/> is neither video nor audio type.<br/>
        ///     -or-<br/>
        ///     The format of packet is not matched with the specified format in the constructor.
        /// </exception>
        /// <exception cref="NoBufferSpaceException">The internal buffer has reached its limits.</exception>
        /// <seealso cref="Player.SetSource(MediaSource)"/>
        /// <seealso cref="MediaStreamConfiguration.BufferMaxSize"/>
        /// <seealso cref="MediaPacket"/>
        /// <since_tizen> 3 </since_tizen>
        public void Push(MediaPacket packet)
        {
            if (_player == null)
            {
                Log.Error(PlayerLog.Tag, "The source is not set as a source to a player yet.");
                throw new InvalidOperationException("The source is not set as a source to a player yet.");
            }

            if (packet == null)
            {
                Log.Error(PlayerLog.Tag, "packet is null");
                throw new ArgumentNullException(nameof(packet));
            }

            if (packet.IsDisposed)
            {
                Log.Error(PlayerLog.Tag, "packet is disposed");
                throw new ObjectDisposedException(nameof(packet));
            }

            if (packet.Format.Type == MediaFormatType.Text || packet.Format.Type == MediaFormatType.Container)
            {
                Log.Error(PlayerLog.Tag, "The format of the packet is invalid : " + packet.Format.Type);
                throw new ArgumentException($"The format of the packet is invalid : { packet.Format.Type }.");
            }

            if (!packet.Format.Equals(_audioMediaFormat) && !packet.Format.Equals(_videoMediaFormat))
            {
                Log.Error(PlayerLog.Tag, "The format of the packet is invalid : Unmatched format.");
                throw new ArgumentException($"The format of the packet is invalid : Unmatched format.");
            }

            if (packet.Format.Type == MediaFormatType.Video && _videoMediaFormat == null)
            {
                Log.Error(PlayerLog.Tag, "Video is not configured with the current source.");
                throw new ArgumentException("Video is not configured with the current source.");
            }

            if (packet.Format.Type == MediaFormatType.Audio && _audioMediaFormat == null)
            {
                Log.Error(PlayerLog.Tag, "Audio is not configured with the current source.");
                throw new ArgumentException("Audio is not configured with the current source.");
            }

            _player.ValidatePlayerState(PlayerState.Paused, PlayerState.Playing, PlayerState.Ready);

            NativePlayer.PushMediaStream(_player.Handle, packet.GetHandle()).
            ThrowIfFailed(_player, "Failed to push the packet to the player");
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Retrieves the album art of the stream, or null if there is no album art data.
        /// </summary>
        /// <returns>Raw byte array if album art exists; otherwise null.</returns>
        /// <remarks>
        /// The <see cref="Multimedia.Player"/> that owns this instance must be in the <see cref="PlayerState.Ready"/>,
        /// <see cref="PlayerState.Playing"/>, or <see cref="PlayerState.Paused"/> state.
        /// </remarks>
        /// <exception cref="ObjectDisposedException">
        /// The <see cref="Multimedia.Player"/> that this instance belongs to has been disposed of.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// The <see cref="Multimedia.Player"/> that this instance belongs to is not in the valid state.
        /// </exception>
        /// <since_tizen> 3 </since_tizen>
        public byte[] GetAlbumArt()
        {
            Player.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);

            NativePlayer.GetAlbumArt(Player.Handle, out var art, out var size).
            ThrowIfFailed(Player, "Failed to get the album art");

            if (art == IntPtr.Zero || size == 0)
            {
                return(null);
            }

            byte[] albumArt = new byte[size];
            Marshal.Copy(art, albumArt, 0, size);
            return(albumArt);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets the metadata with the specified key.
        /// </summary>
        /// <returns>A string that represents the value of the specified key.</returns>
        /// <param name="key">The key to query.</param>
        /// <remarks>
        /// The <see cref="Multimedia.Player"/> that owns this instance must be in the <see cref="PlayerState.Ready"/>,
        /// <see cref="PlayerState.Playing"/>, or <see cref="PlayerState.Paused"/> state.</remarks>
        /// <exception cref="ObjectDisposedException">
        /// The <see cref="Multimedia.Player"/> that this instance belongs to has been disposed of.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// The <see cref="Multimedia.Player"/> that this instance belongs to is not in the valid state.
        /// </exception>
        /// <since_tizen> 3 </since_tizen>
        public string GetMetadata(StreamMetadataKey key)
        {
            Player.ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);

            ValidationUtil.ValidateEnum(typeof(StreamMetadataKey), key);

            IntPtr ptr = IntPtr.Zero;

            try
            {
                NativePlayer.GetContentInfo(Player.Handle, key, out ptr).
                ThrowIfFailed($"Failed to get the meta data with the key '{ key }'");

                return(Marshal.PtrToStringAnsi(ptr));
            }
            finally
            {
                LibcSupport.Free(ptr);
            }
        }