SO, I have been trying to test the CAN Bus communication protocol known as "twai" in the esp32-s2 chip.
I have the chip - Arduino wires - can transceiver (SN65HVD230).
Rx is connected to port4
Tx is connected to port5
the receiving of messages is not working and idk why
the following output shows.
Failed to receive message
Message queued for transmission
Failed to receive message
Message queued for transmission
Failed to receive message
Message queued for transmission
Failed to receive message
Message queued for transmission
Failed to receive message
Message queued for transmission
Failed to receive message
Failed to queue message for transmission
Failed to receive message
Failed to queue message for transmission
Failed to receive message
Failed to queue message for transmission
Failed to receive message
Failed to queue message for transmission
Failed to receive message
Failed to queue message for transmission
Failed to receive message
Failed to queue message for transmission
Failed to receive message
Failed to queue message for transmission
Failed to receive message
Failed to queue message for transmission
Failed to receive message
Failed to queue message for transmission
Failed to receive message
Failed to queue message for transmission
Failed to receive message
Failed to queue message for transmission
Failed to receive message
Failed to queue message for transmission
Failed to receive message
Failed to queue message for transmission
Failed to receive message
Failed to queue message for transmission
this is the code i used, idk what is wrong in it, i got the commands from the espressif link
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/twai.html
it should be similar to the CAN interface in the regular esp32 chip.
this is the code used
#include "driver/gpio.h"
#include "driver/twai.h"
void setup()
{
Serial.begin(115200);
// Initialize configuration structures using macro initializers
twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT(GPIO_NUM_5, GPIO_NUM_4, TWAI_MODE_NORMAL);
twai_timing_config_t t_config = TWAI_TIMING_CONFIG_250KBITS();
twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL();
// Install TWAI driver
if (twai_driver_install(&g_config, &t_config, &f_config) == ESP_OK)
{
printf("Driver installed\n");
} else {
printf("Failed to install driver\n");
return;
}
// Start TWAI driver
if (twai_start() == ESP_OK) {
printf("Driver started\n");
} else {
printf("Failed to start driver\n");
return;
}
}
void loop() {
//Configure message to transmit
twai_message_t message;
message.identifier =0x12;
message.extd =1;
message.data_length_code = 8;
for (int i = 0; i < 8; i++) {
message.data[i] = 0;
}
//Queue message for transmission
if (twai_transmit(&message, pdMS_TO_TICKS(1000)) == ESP_OK) {
printf("Message queued for transmission\n");
} else {
printf("Failed to queue message for transmission\n");
}
delay(2000);
twai_message_t messagerx;
if (twai_receive(&messagerx, pdMS_TO_TICKS(10000)) == ESP_OK) {
printf("Message received\n");
} else {
printf("Failed to receive message\n");
return;
}
//Process received message
if (messagerx.extd) {
printf("Message is in Extended Format\n");
} else {
printf("Message is in Standard Format\n");
}
printf("ID is %d\n", messagerx.identifier);
if (!(messagerx.rtr)) {
for (int i = 0; i < messagerx.data_length_code; i++) {
printf("Data byte %d = %d\n", i, message.data[i]);
}
}
}
This is currently a known issue with the ESP32-S2 devices where TWAI receive does not function properly, while transmit will function correctly. It effects v4.3 of the ESP-IDF TWAI driver as of writing this answer.
EspressIF will be back porting the fix to v4.3 according to this Github issue; https://github.com/espressif/esp-idf/issues/5604 , however does not yet appear to be complete as the pull request is still marked WIP.
I was able to confirm using similar code to yours by switching back to an ESP32 module and receive would then work correctly.
I have the following program through which I can detect the connection failure i.e doBeforeRetry.
Can someone tell me how to detect the successful connection or reconnection. I want to integrate a Health Check program that monitors this connection, but I am unable to capture the event that informs the connections is successfull.
Thanks
requester = RSocketRequester.builder()
.rsocketConnector(connector -> {
connector.reconnect(Retry
.fixedDelay(Integer.MAX_VALUE,Duration.ofSeconds(1))
.doBeforeRetry(e-> System.out.println("doBeforeRetry===>"+e))
.doAfterRetry(e-> System.out.println("doAfterRetry===>"+e))
);
connector.payloadDecoder(PayloadDecoder.ZERO_COPY);
}
).dataMimeType(MediaType.APPLICATION_CBOR)
.rsocketStrategies(strategies)
.tcp("localhost", 7999);
I achieved the detection of successful connection or reconnection with the following approach.
Client Side (Connection initialization)
Mono<RSocketRequester> requester = Mono.just(RSocketRequester.builder()
.rsocketConnector(
// connector configuration goes here
)
.dataMimeType(MediaType.APPLICATION_CBOR)
.setupRoute("client-handshake")
.setupData("caller-name")
.tcp("localhost", 7999)));
One the server side
#ConnectMapping("client-handshake")
public void connect(RSocketRequester requester, #Payload String callerName) {
LOG.info("Client Connection Handshake: [{}]", callerName);
requester
.route("server-handshake")
.data("I am server")
.retrieveMono(Void.class)
.subscribe();
}
On the client side, when I receive the callback on the below method, I detect the connection is successfull.
#MessageMapping("server-handshake")
public Mono<ConsumerPreference> handshake(final String response){
LOG.info("Server Connection Handshake received : Server message [{}]", response.getCallerName());
connectionSuccess.set(true);
return Mono.empty();
}else{
throw new InitializationException("Invalid response message received from Server");
}
}
Additionally, created a application level heartbeat to ensure, the liveliness of the connection.
If you want to know if it's actually healthy, you should probably have a side task that is polling the health of the RSocket, by sending something like a custom ping protocol to your backend. You could time that and confirm that you have a healthy connection, record latencies and success/failures.
I am testing an Xamarin.iOS Application on a real device (iPhone 6s with iOS 12.1) with Xamarin.UITest.
When I am running my few UI Tests, the first test always seam to crash (regardless of what is happening inside the test) due to the same error (see below).
Enviroment is:
Xamarin.UITest 2.2.7
NUnitTestAdapter 2.1.1
NUnit 2.6.3
Xamarin.TestCloud.Agent 0.21.7
Setup is:
[SetUp]
public void Setup(){
this.app = ConfigureApp.iOS
.EnableLocalScreenshots()
.InstalledApp("my.app.bundle")
.DeviceIdentifier("My-iPhone6s-UDID-With-iOS12.1")
.StartApp();
}
[Test]
public void FirstTestThatCouldBeEmpty(){
//But doesn't have to be empty to produce the error
}
Resulting error:
2019-01-17T14:11:20.4902700Z 1 - ClearData:> 2019-01-17T14:11:20.4916340Z bundleId: my.app.bundle
2019-01-17T14:11:20.4929580Z deviceId: My-iPhone6s-UDID-With-iOS12.1
2019-01-17T14:11:33.7561260Z 3 - LaunchTestAsync:
2019-01-17T14:11:33.7574050Z deviceId: My-iPhone6s-UDID-With-iOS12.1
2019-01-17T14:11:33.9279420Z 5 - HTTP request failed, retry limit hit
2019-01-17T14:11:33.9302300Z Exception: System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Unable to read data from the transport connection: Connection reset by peer. ---> System.IO.IOException: Unable to read data from the transport connection: Connection reset by peer. ---> System.Net.Sockets.SocketException: Connection reset by peer
2019-01-17T14:11:33.9322710Z at System.Net.Sockets.Socket.EndReceive (System.IAsyncResult asyncResult) [0x00012] in <23340a11bb41423aa895298bf881ed68>:0
2019-01-17T14:11:33.9340560Z at System.Net.Sockets.NetworkStream.EndRead (System.IAsyncResult asyncResult) [0x00057] in <23340a11bb41423aa895298bf881ed68>:0
2019-01-17T14:11:33.9358740Z --- End of inner exception stack trace ---
2019-01-17T14:11:33.9377100Z at System.Net.Sockets.NetworkStream.EndRead (System.IAsyncResult asyncResult) [0x0009b] in <23340a11bb41423aa895298bf881ed68>:0
2019-01-17T14:11:33.9398100Z at System.IO.Stream+<>c.b__43_1 (System.IO.Stream stream, System.IAsyncResult asyncResult) [0x00000] in <98fac219bd4e453693d76fda7bd96ab0>:0
2019-01-17T14:11:33.9415720Z at System.Threading.Tasks.TaskFactory1+FromAsyncTrimPromise1[TResult,TInstance].Complete (TInstance thisRef, System.Func`3[T1,T2,TResult] endMethod, System.IAsyncResult asyncResult, System.Boolean requiresSynchronization) [0x00000] in <98fac219bd4e453693d76fda7bd96ab0>:0
Sometimes it is this error:
SetUp : Xamarin.UITest.XDB.Exceptions.DeviceAgentException : Unable to end session: An error occurred while sending the request
System.Net.Http.HttpRequestException : An error occurred while sending the request
System.Net.WebException : Unable to read data from the transport connection: Connection reset by peer.
System.IO.IOException : Unable to read data from the transport connection: Connection reset by peer.
System.Net.Sockets.SocketException : Connection reset by peer
What could be a solution to this?
Doing the version puzzle of the nuget packages got me this far, that all tests are working besides this one.
A dummy test would be a possibility, but that would that countinous builds with those test would never be in the state of "successful" because this one test that is failing =(
I was able to find a work around for this issue, and really any issue with the device agent not connecting to the app under test.
public static IApp StartApp(Platform platform)
{
if (platform == Platform.iOS)
{
try
{
return ConfigureApp.iOS
.InstalledApp("com.example")
#if DEBUG
.Debug()
#endif
.StartApp();
}
catch
{
return ConfigureApp.iOS
.InstalledApp("com.example")
#if DEBUG
.Debug()
#endif
.ConnectToApp();
}
}
In plain language : "If you tried to start the app, and something went wrong, try to see if the app under test was started anyway and connect to it"
Note : As https://stackoverflow.com/users/1214857/iupchris10 mentioned in the comments, a caveat to this approach is that when you run tests consecutively, while the StartApp call will in theory reliably shut down the app, with the point of failure being reconnection, if it does not and you are running tests consecutively, you will simply connect to the running app instance in whatever state it was left in. This approach offers no recourse. Xamarin's StartApp will throw Exception, rather than a typed exception, and so mitigating this will rely on you parsing InnerException.Message and keeping a table of expected failures.
I'm trying to set up a socket.io connection, but the connection keeps closing with a transport error message. Both, client and server, are running socket.io v2.0.3.
Client
var _socket = io({
transports: ['websocket'],
query: {
token: userToken,
roomName: getRoomName(),
},
});
messages:
socket.io-client:manager attempting reconnect +5s
socket.io.min.js:1 socket.io-client:manager readyState closed +0ms
socket.io.min.js:1 socket.io-client:manager opening https://video.twoseven.xyz +1ms
socket.io.min.js:1 engine.io-client:socket creating transport "websocket" +1ms
socket.io.min.js:1 engine.io-client:socket setting transport websocket +1ms
socket.io.min.js:1 socket.io-client:manager connect attempt will timeout after 20000 +2ms
socket.io.min.js:2 WebSocket connection to 'wss://video.twoseven.xyz/socket.io/?token=abcd&roomName=us&EIO=3&transport=websocket' failed: Invalid frame header
r.doOpen # socket.io.min.js:2
r.open # socket.io.min.js:2
r.open # socket.io.min.js:1
r # socket.io.min.js:1
r # socket.io.min.js:1
r.open.r.connect # socket.io.min.js:1
(anonymous) # socket.io.min.js:1
socket.io.min.js:1 engine.io-client:socket socket error {"type":"TransportError","description":{"isTrusted":true}} +733ms
socket.io.min.js:1 socket.io-client:manager connect_error +1ms
socket.io.min.js:1 socket.io-client:manager cleanup +0ms
socket.io.min.js:1 socket.io-client:manager reconnect attempt error +1ms
socket.io.min.js:1 socket.io-client:manager will wait 4769ms before reconnect attempt +1ms
socket.io.min.js:1 engine.io-client:socket socket close with reason: "transport error" +0ms
The Chrome developer console reports the following from the network tab:
General
Request URL:wss://video.twoseven.xyz/socket.io/?token=abcd&roomName=us&EIO=3&transport=websocket
Request Method:GET
Status Code:101 Switching Protocols
Response Headers
Connection:upgrade
Date:Thu, 19 Oct 2017 22:36:52 GMT
Sec-WebSocket-Accept:YJ3aZ2L+X+ANa1bJK3ECO/s7XVE=
Sec-WebSocket-Extensions:permessage-deflate
Server:nginx/1.11.8
Upgrade:websocket
Server
const io = new socketio(server, {pingInterval: 3000, pingTimeout: 10000});
io.set('transports', ['websocket']);
messages:
engine handshaking client "yrFJADAHt-QQZsX6AAAA" +0ms
engine:socket sending packet "open" ({"sid":"yrFJADAHt-QQZsX6AAAA","upgrades":[],"pingInterval":3000,"pingTimeout":10000}) +3ms
engine:socket flushing buffer to transport +1ms
engine:ws writing "0{"sid":"yrFJADAHt-QQZsX6AAAA","upgrades":[],"pingInterval":3000,"pingTimeout":10000}" +1ms
engine:transport setting request +1ms
engine:socket sending packet "message" (0) +9ms
engine:socket flushing buffer to transport +19ms
engine:ws writing "40" +1ms
engine:socket sending packet "message" (2["authenticated"]) +91ms
engine:socket flushing buffer to transport +0ms
engine:ws writing "42["authenticated"]" +1ms
engine:socket transport error +136ms
engine:ws closing +2ms
From the server logs, I see that the connection event has been triggered and executes fine except for the last line which says socket.emit('authenticated');. The transport seems to fail at this point
In my application, a user can restart a video from the beginning after it has ended.
To implement this, I have overridden in the custom receiver the receiver library MediaManager.onEnded() method, and send a custom message to the sender, rather than calling resetMediaElement, which is the default behavior of this method.
At this point, the user hits a play button, and the sender calls the RemoteMediaPlayer.play() method, which should cause the receiver library to call the play() method on the <video> element.
But instead, the receiver library sends back a message saying INVALID REQUEST, INVALID_MEDIA_SESSSION_ID.
Also. the receiver library has logged a message saying "
Unexpected command, player is in the IDLE state so the media session ID is not yet valid
But the last state update from the receiver shows the player in the PLAYING state in both the receiver and sender logs.
Here is the receiver log:
::mmOnLoad() mediacast.js:480
url: http://192.168.1.50/apps/chromecast/videos/Inside%20Diamond%20Head-0001.mp4 mediacast.js:498
duration: 0 mediacast.js:500
::showVideo()- message:[object Object] mediacast.js:257
url:http://192.168.1.50/apps/chromecast/videos/Inside%20Diamond%20Head-0001.mp4 mediacast.js:259
::fadeOutOldMediaElement() mediacast.js:384
::mmOnLoad()- presenting video from http://192.168.1.50/apps/chromecast/videos/Inside%20Diamond%20Head-0001.mp4, duration 0 mediacast.js:552
::fadeOutOldMediaElement0() mediacast.js:393
::videoFadedOut()- url: http://192.168.1.50/apps/chromecast/videos/Inside%20Diamond%20Head-0001.mp4 mediacast.js:265
::videoFadedOut()- setting media element [object HTMLVideoElement] mediacast.js:279
::removeMediaElementOrOverlay() mediacast.js:398
::removeOldMediaElement() mediacast.js:432
::removeOverlay() mediacast.js:427
[ 40.701s] [cast.receiver.MediaManager] Metadata loaded
cast_receiver.javascript:574
[ 40.736s] [cast.receiver.MediaManager] Sending broadcast status message
cast_receiver.javascript:574
>>>>>the media element state is paused mediacast.js:603
media element networkState = 2, readyState = 1 mediacast.js:605
[ 40.802s] [cast.receiver.IpcChannel] IPC message sent: {"namespace":"urn:x-cast:com.google.cast.media","senderId":"*:*","data":"{\"type\":\"MEDIA_STATUS\",\"status\":[{\"mediaSessionId\":1,\"playbackRate\":1,\"playerState\":\"PAUSED\",\"currentTime\":0,\"supportedMediaCommands\":15,\"volume\":{\"level\":0.06666666666666667,\"muted\":false},\"media\":{\"customData\":{\"volume\":0.06666666666666667,\"pauseAfter\":true,\"pauseBefore\":true,\"rotation\":0},\"streamType\":\"BUFFERED\",\"duration\":42.4,\"contentType\":\"video/mp4\",\"contentId\":\"http://192.168.1.50/apps/chromecast/videos/Inside%20Diamond%20Head-0001.mp4\",\"metadata\":{\"metadataType\":1}}}],\"requestId\":1}"}
cast_receiver.javascript:574
::videoLoaded() mediacast.js:291
::videoLoaded0() mediacast.js:302
::addVideo() mediacast.js:421
::videoLoaded1() mediacast.js:309
[ 48.434s] [cast.receiver.IpcChannel] Received message: {"data":"{\"type\":\"PLAY\",\"requestId\":2,\"mediaSessionId\":1}","namespace":"urn:x-cast:com.google.cast.media","senderId":"51:name.renkel.james.mediacast-6"}
cast_receiver.javascript:574
[ 48.440s] [cast.receiver.CastMessageBus] Dispatching CastMessageBus message [urn:x-cast:com.google.cast.media, 51:name.renkel.james.mediacast-6]: {"type":"PLAY","requestId":2,"mediaSessionId":1}
cast_receiver.javascript:574
[ 48.446s] [cast.receiver.MediaManager] MediaManager message received [51:name.renkel.james.mediacast-6] {"type":"PLAY","requestId":2,"mediaSessionId":1}
cast_receiver.javascript:574
[ 48.449s] [cast.receiver.MediaManager] Dispatching MediaManager play event
cast_receiver.javascript:574
[ 48.457s] [cast.receiver.MediaManager] onPlay
cast_receiver.javascript:574
[ 48.473s] [cast.receiver.MediaManager] Sending broadcast status message
cast_receiver.javascript:574
>>>>>the media element state is buffering mediacast.js:603
media element networkState = 1, readyState = 4 mediacast.js:605
[ 48.491s] [cast.receiver.IpcChannel] IPC message sent: {"namespace":"urn:x-cast:com.google.cast.media","senderId":"*:*","data":"{\"type\":\"MEDIA_STATUS\",\"status\":[{\"mediaSessionId\":1,\"playbackRate\":1,\"playerState\":\"BUFFERING\",\"currentTime\":0.033322,\"supportedMediaCommands\":15,\"volume\":{\"level\":0.06666666666666667,\"muted\":false}}],\"requestId\":2}"}
cast_receiver.javascript:574
[ 49.071s] [cast.receiver.MediaManager] Buffering state changed, isPlayerBuffering: false old time: 0.033322 current time: 0.433322
cast_receiver.javascript:574
[ 49.077s] [cast.receiver.MediaManager] Sending broadcast status message
cast_receiver.javascript:574
>>>>>the media element state is playing mediacast.js:603
media element networkState = 2, readyState = 4 mediacast.js:605
[ 49.090s] [cast.receiver.IpcChannel] IPC message sent: {"namespace":"urn:x-cast:com.google.cast.media","senderId":"*:*","data":"{\"type\":\"MEDIA_STATUS\",\"status\":[{\"mediaSessionId\":1,\"playbackRate\":1,\"playerState\":\"PLAYING\",\"currentTime\":0.433322,\"supportedMediaCommands\":15,\"volume\":{\"level\":0.06666666666666667,\"muted\":false}}],\"requestId\":0}"}
cast_receiver.javascript:574
::onEnded(VIDEO) mediacast.js:369
::onEnded- network state:1 mediacast.js:370
::onEnded- ready state:4 mediacast.js:371
::onEnded- paused:true mediacast.js:372
::onEnded- ended:true mediacast.js:373
::sendMessage({"indication":"ended"}) mediacast.js:108
[ 90.955s] [cast.receiver.IpcChannel] IPC message sent: {"namespace":"urn:x-cast:name.renkel.james.mediacast","senderId":"51:name.renkel.james.mediacast-6","data":"{\"indication\":\"ended\"}"}
cast_receiver.javascript:574
[110.341s] [cast.receiver.IpcChannel] Received message: {"data":"{\"type\":\"PLAY\",\"requestId\":3,\"mediaSessionId\":1}","namespace":"urn:x-cast:com.google.cast.media","senderId":"51:name.renkel.james.mediacast-6"}
cast_receiver.javascript:574
[110.350s] [cast.receiver.CastMessageBus] Dispatching CastMessageBus message [urn:x-cast:com.google.cast.media, 51:name.renkel.james.mediacast-6]: {"type":"PLAY","requestId":3,"mediaSessionId":1}
cast_receiver.javascript:574
[110.358s] [cast.receiver.MediaManager] Unexpected command, player is in IDLE state so the media session ID is not valid yet
cast_receiver.javascript:574ib cast_receiver.javascript:574gb.Gb cast_receiver.javascript:562B.log cast_receiver.javascript:361E cast_receiver.javascript:412Z.M cast_receiver.javascript:1654W.ra cast_receiver.javascript:1181Hb cast_receiver.javascript:885g.dispatchEvent cast_receiver.javascript:856g.M cast_receiver.javascript:1104Hb cast_receiver.javascript:885g.dispatchEvent cast_receiver.javascript:856g.M cast_receiver.javascript:968
[110.362s] [cast.receiver.MediaManager] Sending error message to 51:name.renkel.james.mediacast-6
cast_receiver.javascript:574
[110.368s] [cast.receiver.IpcChannel] IPC message sent: {"namespace":"urn:x-cast:com.google.cast.media","senderId":"51:name.renkel.james.mediacast-6","data":"{\"requestId\":3,\"type\":\"INVALID_REQUEST\",\"reason\":\"INVALID_MEDIA_SESSION_ID\"}"}
cast_receiver.javascript:574
And here is the sender log:
11-10 13:36:36.631: D/MC_Sender(15051): ::showVideo()- url: http://192.168.1.50/apps/chromecast/videos/Inside%20Diamond%20Head-0001.mp4 11-10 13:36:36.732: D/MC_MainActivity.PagerAdapter(15051): ::setPrimaryItem(0)
11-10 13:36:36.732: D/MC_MainActivity(15051): ::setContentPosition(0)
11-10 13:36:40.325: D/MC_MediaPlayer(15051): ::onMessageReceived(): device-TV Room; namespace-urn:x-cast:com.google.cast.media; message-{"type":"MEDIA_STATUS","status":[{"mediaSessionId":2,"playbackRate":1,"playerState":"PAUSED","currentTime":0,"supportedMediaCommands":15,"volume":{"level":0.06666666666666667,"muted":false},"media":{"customData":{"volume":0.06666666666666667,"pauseAfter":true,"pauseBefore":true,"rotation":0},"streamType":"BUFFERED","duration":42.4,"contentType":"video/mp4","contentId":"http://192.168.1.50/apps/chromecast/videos/Inside%20Diamond%20Head-0001.mp4","metadata":{"metadataType":1}}}],"requestId":4}
11-10 13:36:40.375: D/MC_Listeners(15051): ::onStatusUpdated()- playerState=PAUSED
11-10 13:36:40.426: D/MC_Runner(15051): ::onSenderStateChange(PAUSED)- runState=LOADING
11-10 13:36:40.426: D/MC_Runner(15051): ::setRunState(RUNNING)- stopWhenRunning=false
11-10 13:36:40.426: D/MC_CastFragment(15051): ::runnerUpdate()
11-10 13:36:40.456: D/MC_Listeners(15051): ::onStatusUpdated()- playerState=PAUSED
11-10 13:36:40.456: D/MC_Listeners(15051): ::onMetadataUpdated()- mediaType=MOVIE
11-10 13:36:40.516: D/MC_MainActivity.PagerAdapter(15051): ::setPrimaryItem(0)
11-10 13:36:40.516: D/MC_MainActivity(15051): ::setContentPosition(0)
11-10 13:36:40.806: D/MC_Sender(15051): ::loadMedia()- statusCode: 0; success: true
11-10 13:36:40.806: D/MC_Runner(15051): LoadCallback::callback(true): wasStopped=false
...
11-10 13:38:47.201: D/MC_Sender(15051): ::playMedia()
11-10 13:38:47.391: D/MC_MediaPlayer(15051): ::onMessageReceived(): device-TV Room; namespace-urn:x-cast:com.google.cast.media; message-{"type":"MEDIA_STATUS","status":[{"mediaSessionId":1,"playbackRate":1,"playerState":"BUFFERING","currentTime":0.033322,"supportedMediaCommands":15,"volume":{"level":0.06666666666666667,"muted":false}}],"requestId":2}
11-10 13:38:47.411: D/MC_Listeners(15051): ::onStatusUpdated()- playerState=BUFFERING
11-10 13:38:47.531: D/MC_Runner(15051): ::onSenderStateChange(BUFFERING)- runState=RUNNING
11-10 13:38:47.671: D/MC_MainActivity.PagerAdapter(15051): ::setPrimaryItem(0)
11-10 13:38:47.671: D/MC_MainActivity(15051): ::setContentPosition(0)
11-10 13:38:48.372: D/MC_Sender(15051): ::playMedia()- statusCode: 0; success: true
11-10 13:38:48.382: D/MC_MediaPlayer(15051): ::onMessageReceived(): device-TV Room; namespace-urn:x-cast:com.google.cast.media; message-{"type":"MEDIA_STATUS","status":[{"mediaSessionId":1,"playbackRate":1,"playerState":"PLAYING","currentTime":0.6,"supportedMediaCommands":15,"volume":{"level":0.06666666666666667,"muted":false}}],"requestId":0}
...
11-10 13:39:29.736: D/MC_Listeners(15051): ::onMessageReceived()- nameSpace: urn:x-cast:name.renkel.james.mediacast; message: {"indication":"ended"}
11-10 13:39:29.806: D/MC_Runner(15051): ::onSenderStateChange(ENDED)- runState=RUNNING
...
11-10 13:42:19.918: D/MC_CastFragment(15051): ::onClick()
11-10 13:42:19.918: D/MC_Sender(15051): ::playMedia()
11-10 13:42:20.398: D/MC_MediaPlayer(15051): ::onMessageReceived(): device-TV Room; namespace-urn:x-cast:com.google.cast.media; message-{"requestId":3,"type":"INVALID_REQUEST","reason":"INVALID_MEDIA_SESSION_ID"}
11-10 13:42:20.418: D/MC_Sender(15051): ::playMedia()- statusCode: 1; success: false
I believe that once the video ends, it goes to an IDLE state whether resetMediaElement is called or not. There's different reasons why the status might be IDLE that you can specify: https://developers.google.com/cast/docs/reference/receiver/cast.receiver.media.IdleReason.
It's a bit roundabout, but based on the methods listed at https://developers.google.com/cast/docs/reference/receiver/cast.receiver.MediaManager, you could:
1) check if the video successfully finished playing
2) set the idle reason as cast.receiver.media.IdleReason.FINISHED
Then, in your sender, you can override customizedStatusCallback() to check the status and idle reason and change the status before sending it to your sender so that it can replay correctly.